I'm trying to build an GUI application with Java Swing. There is a button which adds a new JLabel
on click. That's working well, but when the number of labels increases more than the panel size, I can't scroll down.
When I tried to add a JScrollPane
it also doesn't scroll.
How can I create scroll pane which scrolls down when a new component is added?
Code to add a new label
JLabel label = new JLabel("Hello "+i);
label.setBounds(50, y, 100, 100);
pnl.add(label);
pnl.repaint();
y+=10;
i++;