Question

how can i replace a tab of TabPanel with another text.

in the following code i want to replace text4 in tab one.

in other word when a tab show's a widget (like text1) how can i change its content with another widget (like text4)

    public void onModuleLoad() {
    String text1 = "1111111111111111111111111111 ...";
    String text2 = "2222222222222222222222222222...";
    String text3 = "3333333333333333333333333333...";
    String text4 = "4444444444444444444444444444...";

    TabPanel panel = new TabPanel();

    FlowPanel flowpanel;

    flowpanel = new FlowPanel();
    flowpanel.add(new Label(text1));
    panel.add(flowpanel, "One");

    flowpanel = new FlowPanel();
    flowpanel.add(new Label(text2));
    panel.add(flowpanel, "Two");

    flowpanel = new FlowPanel();
    flowpanel.add(new Label(text3));
    panel.add(flowpanel, "Three");

    panel.selectTab(0);

    /* in this line exactlly , How can i raplace text4 in tab(one) */

    panel.setSize("500px", "250px");
    panel.addStyleName("table-center");
    RootPanel.get("demo").add(panel);
}
Was it helpful?

Solution

The simple way is keep label1 and change the value whenever you want

 Label label1 = new Label(text1)
 flowpanel.add(label1);
 ...
 label1.setText(text4);

If you didn't do this then you can do it like that :

FlowPanel f =  (FlowPanel) panel.getWidget(0); // first added Widget (flowpanel)
Label l = (Label) f.getWidget(0); // first added widget to panel (label)
l.setText(text4); // change the text

OTHER TIPS

I think what you need to do is keep a reference to the Label and then change the text for the label. I think that's probably it but it's hard to tell since you say replace text4 which you don't use in that example.

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