Setting size of compnents in a grid Layout Java 1.2
I am using a Grid Layout within a panel as is shown in a section of the code below, but I am
not able to resize the components or to change their properties. Can anyone please
guide me?
JPanel routesPanel = new JPanel();
routesPanel.setLayout(new BoxLayout(routesPanel, BoxLayout.X_AXIS));
JPanel left_panel = new JPanel();
left_panel.setLayout(new GridLayout(4,4,5,1));
routesPanel.add(left_routes_panel);
In the above code, if I add a JTextField to the left_panel for instance, it does not
change the size.
Thanks
Sudz
[596 byte] By [
Sudza] at [2007-11-27 9:34:05]

# 1
I cant imagine what your problem with the above code is, since you aren't adding any components.
Try recreating the problem in a complete code example and re-post that. It the process, you might just realise that it was nothing more than a coding error more than a component feature error.
ICE
# 2
Thanks for responding promptly!
Essentially, what I am doing is
JButton createListButton = new JButton("Create List");
createListButton.setSize(10);
left_panel.add(createListButton);
But with the equal sizing of the GridLayout, the buttons
appear clumsy and setting the size to 10 has no overriding effect.
Sudhama
Sudza at 2007-7-12 22:57:23 >

# 3
Layout managers use the preferred size when attempting to posting the components in the panel, so using setSize() has no effect.
However, the layout manager can ignore the preferred size suggestion if it desires. In the case of a GridLayout, it will resize every component so that the entire space of the panel is filled up.
If you need further help then you need to create a "Short, Self Contained, Compilable and Executable, Example Program (SSCCE)",
see http://homepage1.nifty.com/algafield/sscce.html,
that demonstrates the incorrect behaviour, because I can't guess exactly what you are doing based on the information provided.
Don't forget to use the "Code Formatting Tags",
see http://forum.java.sun.com/help.jspa?sec=formatting,
so the posted code retains its original formatting.