我正在尝试在 GWT 中制作动态 TabPanel。我希望 TabPanel 中的文本根据用户在 TextBox 中键入的内容进行更改。例如,输入“Tab one”会将选项卡文本更改为“Tab one”。但是,我似乎找不到更改选项卡名称的方法。 getTitle() 仅返回标题,而不返回实际文本。有谁知道该怎么做吗?
一种方法可能是删除该选项卡并使用相同的内容重新创建它,但如果可能的话,我真的想避免这种情况。 谢谢。
最佳答案
“onnoweb”已经给出了正确的答案,但这里有一个演示示例。
package stefank.client;
import com.google.gwt.core.client.EntryPoint;
import com.google.gwt.dom.client.Style.Unit;
import com.google.gwt.event.dom.client.ClickEvent;
import com.google.gwt.event.dom.client.ClickHandler;
import com.google.gwt.user.client.ui.Button;
import com.google.gwt.user.client.ui.HTML;
import com.google.gwt.user.client.ui.RootPanel;
import com.google.gwt.user.client.ui.TabLayoutPanel;
public class _02_GWTAnimation implements EntryPoint {
public void onModuleLoad() {
// Create a tab panel
final TabLayoutPanel tabPanel = new TabLayoutPanel(2.5, Unit.EM);
tabPanel.setHeight("100px");
tabPanel.setAnimationDuration(1000);
tabPanel.getElement().getStyle().setMarginBottom(10.0, Unit.PX);
// Add a home tab
String[] tabTitles = {"hello", "world"};
HTML homeText = new HTML("Lorem ipsum");
tabPanel.add(homeText, tabTitles[0]);
// Add a tab
HTML moreInfo = new HTML("Lorem ipsum");
tabPanel.add(moreInfo, tabTitles[1]);
// Return the content
tabPanel.selectTab(0);
tabPanel.ensureDebugId("cwTabPanel");
RootPanel.get().add(tabPanel);
Button changeText = new Button("change Text");
changeText.addClickHandler(new ClickHandler() {
@Override
public void onClick(ClickEvent event) {
tabPanel.setTabText(0, "new Title");
}
});
RootPanel.get().add(changeText);
}
}
关于java - 更改 GWT TabPanel 名称,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12149199/