Components in GridLayout wit JPanel fills the grid incorrectly?

Read the Swing tutorial on Using Layout Managers so you understand the basics of how layout managers work A GridLayout resizes all components to the same size When creating a form you will generally nest different panels using different layout managers to get the effect you desire In this case you might use a FlowLayout for the buttons. Then you might use a GridBagLayout or SpringLayout for the other components.

Read the Swing tutorial on Using Layout Managers so you understand the basics of how layout managers work. A GridLayout resizes all components to the same size. When creating a form you will generally nest different panels using different layout managers to get the effect you desire.In this case you might use a FlowLayout for the buttons.

Then you might use a GridBagLayout or SpringLayout for the other components.

Thank you for your answer, I will try what you suggested. In the meanwhile, I've just created a few panels with grid layouts to place my components better. – Doron Sinai Nov 6 '10 at 23:01.

In any case, I recommend you try MiGLayout for all your layout needs. You'll be surprised by it's simplicity!

GridLayout is a simple layout manager with simple rules. I was going to downvote for the same reason as explained by jackrabbit. I believe people should know how the default layout managers work before using/recommending 3rd party libraries.

– camickr Nov 6 '10 at 15:29 While I agree with this, I believe MiGLayout could be an exception because a) this single layout manager can replace ALL built-in managers b) it's really small in size (~75 kb) and c) bugs.sun. Com/bugdatabase/view_bug. Do?

Bug_id=6530906 (many want it to be included in JDK 7) – pek Nov 6 '10 at 16:21.

The whole point of GridLayout is to layout the components in a regular grid. Your setSize calls will be overridden by the layout manager. Possibly setPreferredSize or setMaximumSize may work, but it is up to the layout manager to decide to take them into account.

1, using setPreferredSize() or setMaximumSize() will have no effect when using a GridLayout. Read the API documentation or read the Swing tutorial. The whole point of a GridLayout is that EVERY component is resized to the size of the largest component added to the grid.

– camickr Nov 6 '10 a "possibly ... may work, but up to the layout manager". The OP can read the documentation too, no? – jackrabbit Nov 6 '10 at 20:37.

BoxLayout is a useful alternative in this context, as seen in this example.

A GridLayout resizes all components to the same size. When creating a form you will generally nest different panels using different layout managers to get the effect you desire. In this case you might use a FlowLayout for the buttons.

Then you might use a GridBagLayout or SpringLayout for the other components.

I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.

Related Questions