I’m having an issue in my application. I wish to dynamically create several “tabbed” scrollpanes that hold a semi-large amount of objects called “ImageLabels”, which are just labels with (you guessed it) images on them.
I made most of my gui in Netbeans, as it is semi-complicated and I’m too nooby to do it myself.
My problem is this: When adding my scrollpane objects (that contain a JPanel with a GridLayout), and after I attempt to add my imagelabels to the JPanel with the layout (my constructor is set to “new GridLayout(0, 5, 5, 5);” which is unlimited rows, 5 columns, with 5 pxls of space.) nothing shows up, nor does the scrollpanel go into “scroll” mode.
I am completely at a loss and have been trying all day with different layouts. Here’s some code I have…
Constructor of the ImageLabel object..
addMouseListener(this);
setVisible(true);
setPreferredSize(new Dimension(32, 32));
How I set up my tileHolderPanel JPanel (the panel holding the ImageLabels)
myLayout = new GridLayout(0, 5, 5, 5);
tileHolderPanel.setLayout(myLayout);
and after constructing all of the ImageLabels I wish to add to each panel, I simply do
tileHolderPanel.add(label);
If it matters, my TileHolderPanel is inside of a scrollpane which is inside a JPanel,and they have the default GroupLayouts which Netbeans generates.
Thank you,
-Luke
Here’s a working example with which to compare your code.