It's not a secret anymore!
The moose likes Swing / AWT / SWT and the fly likes BorderLayout problem Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Java Interview Guide this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "BorderLayout problem" Watch "BorderLayout problem" New topic

BorderLayout problem

alex earnshaw
Ranch Hand

Joined: Nov 05, 2001
Posts: 60
Hi all,
I am using BorderLayout manager to display a JList and a JTable on a JPanel.
The JList is is in the CENTER of a BorderLayout panel called p1.
The JTable is in the CENTER of a BorderLayout panel called p2.
The panel p1 is on the WEST of a container panel p_outer, and p2 is on the CENTER of the same panel.
Now the problem is -
If I start off with an empty JList and JTable, and then add an item to the JList, the JList appears to decrease in size horizontally and the JTable increases by the same amount. The opposite happens when I remove the item from the JList.
Nothing happens when I add or remove items from the JTable.
I assume that when an item is added to the JList is it releases some space, and then the JTable (which is in the CENTER of the outer panel) uses it up. Is there any way to make the horizontal size of the JList static regardless of whether it contains items or not, and without specifying an actual size (as I don't know in advance the length of the items it's going to contain)

Any help appreciated
Terence Doyle
Ranch Hand

Joined: May 30, 2001
Posts: 328
Hi Alex,
First of all you seem to have too many panels. Why not put the list and the table directly into the outer panel( each of them perhaps in a JScrollPane ... ) ? - less components means less painting and gives you a faster application
Next, you must realize that BorderLayout only respects preferred width of the components at east and west. You could set max, min, height, etc., but the BorderLayout manager would only check to see the preferred width.
Now, knowing that, we have to think about what value a panel or list ( whatever component you have at west in the outer panel ) will report back when we ask it.
Try printing out the preferred sizes from a list listener event method to see how the object at west is reacting to the adding/removing of items to the list.

Hope that helps,

Raising Flares debut album 'Ignition' out now

Terry Doyle <br />SCPJ 1.4 , SCWCD , SCMAD(Beta)
I agree. Here's the link:
subject: BorderLayout problem
It's not a secret anymore!