Granny's Programming Pearls
"inside of every large program is a small program struggling to get out"
JavaRanch.com/granny.jsp
Win a copy of Java Database Connections & Transactions (e-book only) this week in the JDBC forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Devaka Cooray
  • Knute Snortum
  • Paul Clapham
  • Tim Cooke
Sheriffs:
  • Liutauras Vilda
  • Jeanne Boyarsky
  • Bear Bibeault
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Ron McLeod
  • Piet Souris
  • Frits Walraven
Bartenders:
  • Ganesh Patekar
  • Tim Holloway
  • salvin francis

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

 
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
 
Author
Posts: 974
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:

 
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 ]
 
Greenhorn
Posts: 10
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yep

 
Greenhorn
Posts: 5
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
 
Rancher
Posts: 3042
22
  • 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.
 
I'm still in control here. LOOK at this tiny ad!
how do I do my own kindle-like thing - without amazon
https://coderanch.com/t/711421/engineering/kindle-amazon
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!