I want to put a panel with flowlayout in the north area of a borderlayout frame. When the frame is resized, I want the North panel to resize to fit any components that flow to the next line. What I get is components dropping off the end of the North flowlayout to never never land when the boundry is too small. Can this even be done? Is there some update on the borderlayout I should be calling?
Joined: Aug 07, 2000
I'm close. I found that if I subclass JPanel and override getPreferredSize() I can change the size of the North. But now I need a way to calculate the required area. getMinimumSize always returns the same size.
Try looping through each of the components in the flowlayout panel. Use getY() (or getLocation()) to figure out which components are on the last row and how far down it is, and use getHeight() (or getSize()) on each of the last-row components to figure out to overall height of that row. Add the Y of the last row to the largest height from the last row to get the overall preferred height of the component - maybe add a few pixels for cosmetic purposes. There are probably other, better ways to do this with a different combination of layout managers, but I'm too tired to think about that now.
"I'm not back." - Bill Harding, Twister
subject: FlowLayout JPanel in BorderLayout.North??