Hi All, Here is the scenario. I have 3 JPanels, with each of them having a preferred size that is different. Here are the sizes: Main JPanel: 650,280 Left JPanel: 50,280 Middle JPanel: 25,280 Right JPanel: 200,280 I want to add the 3 JPanels to the Main JPanel. I am using the default FlowLayout manager. When I add these JPanels, they all look the exact same size. I thought that FlowLayout manager is supposed to honor the preferred size of components. Is JPanel not considered a component? How can I fix this? Many thanks to you!!!
Hi Barry, You are correct, the FlowLayout does honor preferred sizes. You are probably not setting the preferred size. If you are setting the size you are not setting the preferred size, since a JPanel has a default layout manager that will supply a preferred size if one is not given by the UI. The following code shows an example which works as you would expect.
Hi Manfred, I am setting the preferred size of each JPanel. The only thing that is different between your code and mine is that my main panel (the one that has 3 JPanels in it) is actually a south panel. So, I have a north panel and a south panel (which is the main panel) under that. I also set the preferred size of the south (or main) panel. The north panel also has a preferred size set and uses the GridBagLayout. Can you see anything here that may cause a problem? The north panel does not seem to have any problems. Only the 3 panels in the south panel look exactly the same size, as if it totally ignores the preferred size of each of the 3 panels. Thanks for your help! Barry
subject: Does FlowLayout honor the preferred size of a JPanel?