我如何用另一个文本替换TabPanel的选项卡。
在下面的代码中,我想替换选项卡一中的text4。
换句话说,当选项卡显示的是一个小部件(例如text1)时,如何更改另一个小部件(例如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);
}
最佳答案
简单的方法是保留label1并随时更改值
Label label1 = new Label(text1)
flowpanel.add(label1);
...
label1.setText(text4);
如果您不这样做,则可以这样:
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