This week's book giveaway is in the OCAJP forum. We're giving away four copies of OCA Java SE 8 Programmer I Study Guide 1Z0-808 and have Jeanne Boyarsky & Scott Selikoff on-line! See this thread for details.
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)
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.