I have a problem with a program I'm working on. No matter how much I've read the Swing tutorial (at Sun's site), and the API, I haven't got it fixed.
The problem is as follows:
I have an Applet with JPanels inside JPanels (to make it easier to group the components), and it appears that only the topmost container (in the containment hierachy, the content pane) respects the widow size, while any container it contains, don't, so some of the components end up outside the window.
Here's a program to demonstrate the problem (I'm using JFrame, rather than JApplet, here. The effect is the same). The following works:
--- Start program ---
JFrame frame=new JFrame("Test frame");
JPanel pane=new JPanel();
pane.add(new JTextField(8)); // Add some components
//JPanel paneN=new JPanel();
--- End program ---
This lays out the textfields neatly in two rows of four each, so the layout works.
If you uncomment the two lines above, and changes the line below to "frame.setContentPane(paneN)", it puts all the textfields in a JPanel (as before), and adds that JPanel to a new JPanel, which gets used as the content pane (instead of the first one).
If you run this, it will now lay all the textfields in one line, and they will overflow the window, so some aren't shown.
Is this how it's supposed to be?
Is there some way to get JPanels (or other JComponents) inside others, to all be laid out correctly?
Any help greatly appreciated.