BorderLayout - how to fix size

hello everyone,

I have some problem with my BorderLayout, to put it more precisely with a CENTER region.

I would like to make it fixed size.

I setPrefferedSize(new Dimention(50,50)) for my NORTH and SOUTH regions and I setMinimumSize and setMaximumSize for my CENTER. but my CENTER looks like ignore me. It get smaller when I reduce my frame and vice versa.

this is my code, just in case:

Container pane = getContentPane();
JButton button = new JButton("Button 1 (PAGE_START)");
button.setPreferredSize(new Dimension(0,100));
//button.setMaximumSize(new Dimension(60,60));
//button.setMinimumSize(new Dimension(400,400));

pane.add(button, BorderLayout.PAGE_START);

button = new JButton("Button 2 (CENTER)");

pane.add(button, BorderLayout.CENTER);
button.setMinimumSize(new Dimension(20,20));
button.setMaximumSize(new Dimension(60,60));
//button.setPreferredSize(new Dimension(50,50));
button = new JButton("Button 3 (LINE_START)");

pane.add(button, BorderLayout.LINE_START);

button = new JButton("Long-Named Button 4 (PAGE_END)");
//button.setPreferredSize(new Dimension(0,100));
button.setMinimumSize(new Dimension(20,20));
pane.add(button, BorderLayout.PAGE_END);

button = new JButton("5 (LINE_END)");
pane.add(button, BorderLayout.LINE_END);

is it possible to persuade CENTER to keep there size unchangeable.

Thank you.
[1536 byte] By [andrew_bc] at [2007-11-20 0:17:04]
# 1 Re: BorderLayout - how to fix size
You could try setting the preferred size for your CENTER component...
But if you read the JavaDoc for BorderLayout, you'll see that the principle is that the CENTER area sizes horizontally and vertically to occupy any space not taken by the border areas. Consequently, you should probably use a different layout manager if you want a user-defined constant size for the central area.

There are many different border layouts in the JDK, and their use is explained here: How To Lay Out Components (http://java.sun.com/docs/books/tutorial/uiswing/layout/index.html).

There are also several excellent open source layout managers, such as SGLayout, RiverLayout, etc., which you can find if you Google for Java Layout Managers.

A good programmer is someone who looks both ways before crossing a one-way street...
Doug Linder
dlorde at 2007-11-10 2:18:48 >