Hi all. I should begin by letting you know that i am fairly new to swing, so please forgive my lack of knowledge.
Here's my problem. Im trying to create a GUI with multiple panels. I've created a root panel or contentPanel for all other panel to be placed onto. At the top of this panel, occupying 1/3 of the screen I have created a header panel, which itself will contain two more panels, search and book. Within these two panels (search and book) my components are centred. However i would like the components to flow from the top of the panel. I'm using a GridBagLayout for these two panels(search and book) and i tried to use the setAnchor(GridBagConstraints.PAGE_START) method to align the components with no joy.
Any ideas or helpful comments would be greatly appreciated
Here's my problem... ...Within these two panels (search and book) my components are centred. However i would like the components to flow from the top of the panel. I'm using a GridBagLayout for these two panels(search and book) and i tried to use the setAnchor(GridBagConstraints.PAGE_START) method to align the components with no joy.
When asking questions about laying out compomenents, you may do well to give a much more detailed description of what you are trying to accomplish, that or post an image of what you want to create. Compilable and runnable code would also help quite a bit. We have to see it, either literally or figuratively, to understand it.
generally indicates not setting gridBagConstraint's weightx/weighty. (read the apidocs for detailed explanation)
do you really need to use a GridBagLayout? perhaps a JSplitPane might be easier to give you the 1/3 & 2/3 split
Paul Murphy
Greenhorn
Joined: Jan 03, 2002
Posts: 6
posted
0
Hi guys
I must apologise about the confusing post. I should probably just said that my problem was aligning components (JLabel, JTextField, JButton) in a panel which uses GridBagLayout.
Michael you were right about the GridBagConstraints weightx and weighty. That fixed the problem for me. But i've since changed the layout to a GroupLayout. Seems to be the more sensible option...at least till i meet another problem.