This week's book giveaways are in the Java EE and JavaScript forums.
We're giving away four copies each of The Java EE 7 Tutorial Volume 1 or Volume 2(winners choice) and jQuery UI in Action and have the authors on-line!
See this thread and this one for details.
The moose likes GWT and the fly likes How to force HorizontalPanel to wrap Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
JavaRanch » Java Forums » Frameworks » GWT
Bookmark "How to force HorizontalPanel to wrap" Watch "How to force HorizontalPanel to wrap" New topic
Author

How to force HorizontalPanel to wrap

Jerry Storm
Greenhorn

Joined: Apr 15, 2011
Posts: 6
I have the following:
VerticalPanel
HorizontalPanel
Widget, Widget ...

As I add children widgets to HorizontalPanel, it grows wider and finally adds a scroll bar since it becomes too wide.
I want it to start wrapping children once it reaches certain width, say 90% of the browser window.

How do I do it?
Maneesh Godbole
Saloon Keeper

Joined: Jul 26, 2007
Posts: 10268
    
    8

From the API docs of HorizontalPanel
A panel that lays all of its widgets out in a single horizontal column.
So wrapping is not possible.
If you want wrapping, check out FlowPanel

[How to ask questions] [Donate a pint, save a life!] [Onff-turn it on!]
Jerry Storm
Greenhorn

Joined: Apr 15, 2011
Posts: 6
I tried FlowPanel. It placed all child widgets vertically, not horizontally. I tries to set width to no avail.
Maneesh Godbole
Saloon Keeper

Joined: Jul 26, 2007
Posts: 10268
    
    8

Check out this example http://examples.roughian.com/index.htm#Panels~FlowPanel
Jerry Storm
Greenhorn

Joined: Apr 15, 2011
Posts: 6
My application generates widgets from external data.
I don't know in advance how many widgets will be in a row.
I want them placed in a row from left to right and then when reached the right edge of the window wrap into a new row.
Maneesh Godbole
Saloon Keeper

Joined: Jul 26, 2007
Posts: 10268
    
    8

Did you check the example? It does exactly what you require.
Jerry Storm
Greenhorn

Joined: Apr 15, 2011
Posts: 6
Sorry, I was confused. It seems to work. There are a couple of issues here:
- widgets spill over the bottom when a lot are added, I want to have a vertical scrollbar instead of this
- how do I set the width of the flowpanel to about 90% of the screen?
Maneesh Godbole
Saloon Keeper

Joined: Jul 26, 2007
Posts: 10268
    
    8

Window#getClientWidth gives you the available width.
Based on this you can compute and use FlowPanel#setWidth()
Check out ScrollPanel. You can wrap your FlowPanel inside the ScrollPanel and then add the ScrollPanel to the parent container
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: How to force HorizontalPanel to wrap