Question

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??

Was it helpful?

Solution 2

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.

OTHER TIPS

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");
}

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

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top