3

I'm trying to use a flowpanel in java gwt but when I add different widgets, the panel adds every widget in a new line, here is how I set the flowPanel

 public class Test extends Composite {
   public abstract class SomeWidget<T> extends Composite {
      ...
   }

   public class SomeStringWidget extends SomeWidget<String> {
      ...
   }


   public void setWidget() {
     FlowPanel fp = new FlowPanel();
     fp.setWidth("100%");
     fp.add(new SomeStringWidget());
     fp.add(new SomeStringWidget());
     ...
   }
 }

Why is every Widget set in a new line and not, as the flowpanel should, add the widgets in a line till there is no more space and then add them in a new line??

wasp256
  • 5,943
  • 12
  • 72
  • 119

3 Answers3

7

Flow Panel generates a DIV-Element with the Style GWT-FlowPanel. If you want that you inner Widgets are inline make the CSS of the inner Widgets with the following CSS:

.SomeStringWidget {
   display: inline;
}

or

.SomeStringWidget {
    display: inline-block; 
}

or

.SomeStringWidget {
   float: left;
}

And in your widget set the CSS Class .SomeStringWidget in the constuctor.

public SomeStringWidget {
    this.setStyleName("SomeStringWidget");
}
Sam
  • 2,707
  • 1
  • 23
  • 32
3

I was facing same issue and assigned style to FlowPanel widget to align widgets in a line. This will solve your problem.

FlowPanel fp = new FlowPanel();
fp.setStyleName("flowPanel_inline");

style.css

.flowPanel_inline
{
    display:inline;
}

Also you have to set this same style in added elements also.

bNd
  • 7,512
  • 7
  • 39
  • 72
  • you have to set this styles in all elements which you are going to add in it. I don't know what type widget you added. but it's required. – bNd Feb 04 '13 at 12:44
  • try with different styles like `float: left` or `display: inline;` or `display: inline-block;` as @Sam suggest. because chrome may have some issue with it. – bNd Feb 04 '13 at 13:27
  • you don't have to set this style at fp... only in the inne widgets. – Sam Feb 04 '13 at 15:33
0

If your SomeStringWidget is a Label, then it will always be a new line. If you don't want the newline, use InlineLabel.

Phuah Yee Keat
  • 1,572
  • 1
  • 17
  • 17