brakebg
brakebg

Reputation: 414

Add LayoutPanel to RootPanel by wrapper

i have the following problem which seems quite simple but i have spent more than 2 hours and can't solve it.

Look at the following example.

public class HeaderForm extends VerticalPanel
{
public HeaderForm()
{
Label label = new Label("Some text here which should be visible");
   this.add(lable);

}
}

Here is the entry point

public class SomeApp implements EntryPoint
{

public void onModuleLoad()
{

 HeaderForm instance = new HeaderForm();
 RootPanel.get().add(instance);
}

.... after this we should see the label text ,right? but nothing...

It's quite weird to me, if i do the same but directly without wrapper class... it works fine.

Please, advice.. so simple but does not work.

Upvotes: 0

Views: 276

Answers (1)

glenn
glenn

Reputation: 318

I believe what you want to do is create a new Widget. Your class HeaderForm should extend Composite, and then you can make a VerticalPanel and add your label to it. The VerticalPanel is then initialised using initWidget.

public class HeaderForm extends Composite
{
 public HeaderForm()
 {
    VerticalPanel verticalPanel = new VerticalPanel();
    Label label = new Label("Some text here which should be visible");
    verticalPanel.add(label);
    initWidget(verticalPanel);
 }
}

You can now make an instance of your custom widget in your EntryPoint. Correct me if I made any mistakes. If you want to add other things to your VerticalPanel you can make a function to return the VerticalPanel or to add other Widgets to it directly.

Hope this solved your problem :) Cheers!

Upvotes: 2

Related Questions