problems using a scrollpane with multiple labels and scrolling correctly
Posted on 2006-07-14
I'm trying to load a new label each time a particular button is pressed. This works fine until I try to add the panel with the labels to a scrollpane, which is also then part of a splitpane. The problem is that the labels only fill up the set size of the panel, and the scroll bars only scroll through the set size of the panel as well.
The labels are loaded repeatedly within the actionPerformed method for the button, as follows:
SignPanel.icon = new ImageIcon(blob.getBytes(1L, (int) blob
JLabel label = new JLabel();
panel2 and the scrollpane are loaded within the the buildFrame method, as follows, and then added as normal to the splitpane:
panel2 = new JPanel();
TitledBorder aboveTopBorder2 = BorderFactory.createTitledBorder
panel2.setPreferredSize(new Dimension(800, 175));
JScrollPane scroll2 = new JScrollPane(panel2,
JSplitPane sp = new JSplitPane(JSplitPane.VERTICAL_SPLIT, scroll2, panel3);
(panel3 is just a standard panel with a textfield and a couple of buttons)
I really can't see why this won't work. I've tried every alternative I can think of and it still won't work properly. The labels simply fill the size of the panel and the scrollbars won't scroll beyond the set size of panel2.
Does anybody know how to correct this and allow the labels to be continuosly added to the panel, with the scrollbars scrolling vertically through the panel as you add more labels beyond the set size of the panel. In effect, the scrollbars only seem to be affected by resizing the panel, and not by adding the labels to the panel.
Any help or advice is appreciated.