This week's book giveaway is in the Big Data forum.
We're giving away four copies of Elasticsearch in Action and have Radu Gheorghe & Matthew Lee Hinman on-line!
See this thread for details.
The moose likes Swing / AWT / SWT and the fly likes Swing- FlowLayout inside BorderLayout Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Elasticsearch in Action this week in the Big Data forum!
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "Swing- FlowLayout inside BorderLayout" Watch "Swing- FlowLayout inside BorderLayout" New topic

Swing- FlowLayout inside BorderLayout

David Kowalski

Joined: Mar 06, 2013
Posts: 2
I'm new to swing I have been reading about the flow and border and I'm quite sure I know how they work.
But well I can't figure out one thing, when I put FlowLayout with let's say 5 buttons inside border layout as the north panel and what I'm trying to do is when I resize the window I want the buttons to not dissappear but instead show in new line, it is working with just FlowLayout but inside border when I have something under the north panel the buttons are just hidden.
I have been trying to do this using PreferredLayoutSize.
The thing I would like to know, where do I have to put the dimension from PreferredLayoutSize to make it work?

Thanks for answers.
Campbell Ritchie

Joined: Oct 13, 2005
Posts: 41104
Welcome to the Ranch
Why do you want flow layout at all? Inside border layout the components will shrink as the whole display is shrunk. A flow layout needs to retain enough area to display all its cotained components, otherwise they fall off the end and disappear.
Try a 5×1 grid layout instead, or a horizontal box layout.
Rob Camick
Ranch Hand

Joined: Jun 13, 2009
Posts: 2266
Unfortunately the FlowLayout doesn't automatically increase the preferred height of the component once the components wrap to a new row.

You can use Wrap Layout which extends FlowLayout to provide this functionality.
I agree. Here's the link:
subject: Swing- FlowLayout inside BorderLayout