frame layout
In a very simple frame created with:
f =new javax.swing.JFrame("test frame");
i get the layout:
jTextArea1.append(f.getLayout().getClass().getName());
and obtain: java.awt.BorderLayout.
well, if i put a JTextField on the frame, after resize it occupies all the form. Right. But if I do the following:
f.setLayout(null);
Another jTextArea1.append(f.getLayout().getClass().getName());
tells me that the frame layoutremains BorderLayout!!
At the beginning I thought that what doesn't work
is setLayout (infact the correct method is f.getContentPane().setLayout(...)).
No! because somethingdoes happen! After f.setLayout(null) which should have no effect, the controls stop resizing... so it effectively changes something! Aagh!
Does anyone have an idea of what's appening behind the scenes here?
thanks in advance
Agostino
This is only an assumption, and I will probably be ripped for it, but my guess goes as follows:
Frame and its contentpane both have a layout. The one you want to change and work with, is the one in contentpane. The layout in frame is what controls where the frame places its menubar and where it places the contentpane and anything else that might be directly contained in the frame.
It's because you're using JDK 1.5+.
From 1.5, JFrame.setLayout() is overridden to call getContentPane().setLayout(). So you've actually set the layout on the content pane. I rather assume (don't have the source to hand) that they've not overridden getLayout() accordingly.
Either way, if you use the correct methods all is well :o)
Personally I'm not convinced they did the right thing by overriding the methods in 1.5 but there you go.
It's exactly as you've sed, itchy. They have overridden the setLayout method without to override the getLayout accordingly.
The problem is that I substantilally ignore many swing issues due to the bad idea of using NetBeans gui builder to design forms.
I think that specially LayoutManager such as GridBagLayouts have sense only if hand-coded. Usign a form designer like netbeans gives you the assurance of not-facing the not-so-easy swing logic. And when the things get more complex, designer stop work correctly while you neither access the code that it has generated!!!
thanks agostino