Hey all I have the following java code that simply has a few swing JLabel, JPanel, and JScrollPanel.
I seem to not be able to have the labels that are inside the pane (546211) to cause the scroll to activate vertically. Right now, with me adding to the labels inside and having some off scene, it still does not scroll to those.
This is what my design looks like:
And for testing I shorten the height so that the last label is not viewable:
But when I run it, I am unable to scroll to see that label:
As you can see from the image above my scroll is there but it has no value. The scroll should be there since I put a label out of scene that I would need to scroll down to in order to see it.
Hopefully it's just something I am overlooking for the JScrollPane. Or perhaps I have something out of order?
My java code:
static JPanel panel; private JFrame frame; public static void main(String[] args) { EventQueue.invokeLater(new Runnable() { public void run() { try { tester window = new tester(); } catch (Exception e) { e.printStackTrace(); } } }); } public tester() { initialize(); } private void initialize() { Image imgBG = new ImageIcon(this.getClass().getResource("/background.png")).getImage(); Image imgAvatar = new ImageIcon(this.getClass().getResource("/blank.png")).getImage(); panel = new JPanel(); panel.setLayout(null); JLabel lblLabelBG = new JLabel(""); lblLabelBG.setBounds(10, 3, 635, 129); lblLabelBG.setIcon(new ImageIcon(imgBG)); lblLabelBG.setBackground(new Color(204, 102, 0)); JLabel AvatarImg = new JLabel(""); AvatarImg.setIcon(new ImageIcon(imgAvatar)); AvatarImg.setBounds(5, 4, 100, 111); panel.add(AvatarImg); JLabel lblPH = new JLabel(); lblPH.setFont(new Font("Segoe UI", Font.BOLD, 25)); lblPH.setBounds(15, 110, 172, 22); lblPH.setText("555-555-5555"); panel.add(lblPH); JLabel lblRX = new JLabel(); lblRX.setFont(new Font("Segoe UI", Font.BOLD, 25)); lblRX.setBounds(55, 170, 157, 22); lblRX.setText("546211"); panel.add(lblRX); panel.add(lblLabelBG); JScrollPane scrollPane = new JScrollPane(panel); scrollPane.setBackground(new Color(153, 153, 102)); scrollPane.setBounds(10, 11, 743, 156); scrollPane.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_NEVER); scrollPane.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_ALWAYS); JFrame frame = new JFrame(""); frame.getContentPane().setBackground(new Color(240, 240, 240)); frame.getContentPane().setLayout(null); frame.setSize(785, 291); frame.getContentPane().add(scrollPane); frame.setVisible(true); }