• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

in flow lay out how can i force to add component on next line?

 
Arun Maalik
Ranch Hand
Posts: 216
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hey Ranchar i would like to know one thing that as we know that flow lay out arrange component from left to right and work as word wrapping feature of ms word well but i want by flow lay out that after adding two component next component should be added on the next line how can i accomplise that ?

Regard

Arun
 
Brian Cole
Author
Ranch Hand
Posts: 903
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You can't.

ok, nothing is impossible and there are some creative ways (read: "hacks") I can think of that might force FlowLayout to do something like this. But the easiest way to achieve the effect you want is to have two nested Containers within your Container. It would look something like this:

 
Mathias Nilsson
Ranch Hand
Posts: 367
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I guess you can set the preferredSize to your FlowLayout panel. When the next is added to the panel it's added on a new row.
[ January 08, 2007: Message edited by: Mathias Nilsson ]
 
Pavan Kumar
Greenhorn
Posts: 10
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yep

 
Abhijeet Bhanjadeo
Greenhorn
Posts: 4
AngularJS Flex Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Adding the help for Vertical layout for BoxLayout.
Following line of code will help setting vertical layout of components in the Panel.


Code Sourced from Stackoverflow
 
Rob Camick
Ranch Hand
Posts: 2566
9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
i want by flow lay out that after adding two component next component should be added on the next line


That is not the way FlowLayout is designed to work. You need to use a different layout manager or combination of layout managers:

1. You could use a GridLayout. For example. GridLayout layout = new GridLayout(0, 2); This will wrap components to a new line after 2 columns have been filled. However, all components will be the same size.

2. You could use a GridBagLayout. In this case you need to specify the row/column of each component you add so you manually create your grid.

3. You could use a vertical BoxLayout. Then you create child panels to add to the layout. Each child panel can contain a panel using a FlowLayout with two components.

Read the Swing tutorial on Layout Managers for more information and examples.

You can also have the FlowLayout dynamically flow components to a new line as the components fill the current line. So as the frame is resized the components will wrap as required. See: Wrap Layout.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic