Hi all, I am having a JPanel in which I am adding JLabel,JButton,JComboBox etc. I want to make this
JPanel scrollable. I am using the code as follows. But although I am getting the scrollbar it is not active. Only that bar is coming on the right side of my JFrame(jf). Can anybody suggest me a way out?
JPanel jp = new JPanel();
jp.setLayout(null);
JLabel label = new JLabel("Image");
label.setFont(new Font("Serif", Font.BOLD, 15));
label.setBounds(250,220,250,20);
label.setForeground(Color.white);
jp.add(label);
JPanel panelToScroleOver = new JPanel();
panelToScroleOver.setLayout(new BorderLayout());
panelToScroleOver.add(jp);
JScrollPane editorScroll = new JScrollPane(panelToScroleOver);
editorScroll.setVerticalScrollBarPolicy(JScrollPan e.VERTICAL_SCROLLBAR_ALWAYS);
editorScroll.setHorizontalScrollBarPolicy(JScrollP ane.HORIZONTAL_SCROLLBAR_NEVER);
JTabbedPane documents = new JTabbedPane();
documents.add("doc1", editorScroll);
documents.setPreferredSize(new Dimension(50, 500));
jf.getContentPane().setLayout(new BorderLayout());
jf.getContentPane().add(editorScroll);
jf.setPreferredSize(new Dimension(300, 300));
jf.setVisible(true);
If I add a JTextPane object to the panelToScroleOver panel then that textpane is scrolling. How to make my panel (jp ) to scroll?
Thanks,
Meera.
JPanel scrollable. I am using the code as follows. But although I am getting the scrollbar it is not active. Only that bar is coming on the right side of my JFrame(jf). Can anybody suggest me a way out?
JPanel jp = new JPanel();
jp.setLayout(null);
JLabel label = new JLabel("Image");
label.setFont(new Font("Serif", Font.BOLD, 15));
label.setBounds(250,220,250,20);
label.setForeground(Color.white);
jp.add(label);
JPanel panelToScroleOver = new JPanel();
panelToScroleOver.setLayout(new BorderLayout());
panelToScroleOver.add(jp);
JScrollPane editorScroll = new JScrollPane(panelToScroleOver);
editorScroll.setVerticalScrollBarPolicy(JScrollPan e.VERTICAL_SCROLLBAR_ALWAYS);
editorScroll.setHorizontalScrollBarPolicy(JScrollP ane.HORIZONTAL_SCROLLBAR_NEVER);
JTabbedPane documents = new JTabbedPane();
documents.add("doc1", editorScroll);
documents.setPreferredSize(new Dimension(50, 500));
jf.getContentPane().setLayout(new BorderLayout());
jf.getContentPane().add(editorScroll);
jf.setPreferredSize(new Dimension(300, 300));
jf.setVisible(true);
If I add a JTextPane object to the panelToScroleOver panel then that textpane is scrolling. How to make my panel (jp ) to scroll?
Thanks,
Meera.
Comment