TabLayoutPanel 禁用 Tab GWT

发布于 2024-10-19 07:04:55 字数 78 浏览 3 评论 0原文

如何禁用 TabLayoutPanel 中的选项卡(即用户单击选项卡时无法打开该选项卡)?我在网上搜索但无法找到解决方案

谢谢

How can i disable a tab (i.e the user cannot open the tab when he clicks on it) in the TabLayoutPanel?I searched online but was not able to find a solution

Thanks

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

陌路黄昏 2024-10-26 07:04:55

使用 BeforeSelectionHandler

TabLayoutPanel myPanel = new TabLayoutPanel();
// Add children...

myPanel.addBeforeSelectionHandler(new BeforeSelectionHandler<Integer>() {
  @Override
  public void onBeforeSelection(BeforeSelectionEvent<Integer> event) {
    // Simple if statement - your test for whether the tab should be disabled
    // will probably be more complicated
    if (event.getItem() == 1) {
      // Canceling the event prevents the tab from being selected.
      event.cancel();
    }
  }
});

如果您希望禁用选项卡的样式与启用选项卡的样式不同,可以使用 < code>TabLayoutPanel#getTabWidget 获取选项卡小部件并为其添加样式名称。

Use a BeforeSelectionHandler:

TabLayoutPanel myPanel = new TabLayoutPanel();
// Add children...

myPanel.addBeforeSelectionHandler(new BeforeSelectionHandler<Integer>() {
  @Override
  public void onBeforeSelection(BeforeSelectionEvent<Integer> event) {
    // Simple if statement - your test for whether the tab should be disabled
    // will probably be more complicated
    if (event.getItem() == 1) {
      // Canceling the event prevents the tab from being selected.
      event.cancel();
    }
  }
});

If you want to style the disabled tab differently than enabled tabs, you can use TabLayoutPanel#getTabWidget to get the tab widget and add a style name to it.

很酷不放纵 2024-10-26 07:04:55

对于稍后遇到此问题的任何人:

从 GWT 版本 1.6 开始,禁用/启用选项卡内置于 GWT 中。
TabBar 类有一个方法 setTabEnabled(int index, booleanenabled),用于启用/禁用给定索引处的选项卡。

例如,要禁用 TabPanel 中的所有选项卡:

TabPanel myTabPanel = new TabPanel();
// Add children

TabBar tabBar = myTabPanel.getTabBar();
for(int i=0; i<tabBar.getTabCount(); i++) {
    tabBar.setTabEnabled(i, false);
}

请参阅 GWT javadoc 了解更多信息。

以不同方式设置禁用选项卡的样式(GWT 自动执行此操作,但如果您想更改样式):禁用的 tabBarItem div 会被赋予另一个 CSS 类:gwt-TabBarItem-disabled

For anyone who comes across this later:

As of GWT version 1.6, disabling/enabling tabs is built into GWT.
The TabBar class has a method setTabEnabled(int index, boolean enabled) that enables/disables the tab at a given index.

For example, to disable all the tabs in a TabPanel:

TabPanel myTabPanel = new TabPanel();
// Add children

TabBar tabBar = myTabPanel.getTabBar();
for(int i=0; i<tabBar.getTabCount(); i++) {
    tabBar.setTabEnabled(i, false);
}

See the GWT javadoc for more info.

To style disabled tabs differently (which GWT does automatically, but if you wanted to change the style): disabled tabBarItem divs are given another CSS class: gwt-TabBarItem-disabled.

月竹挽风 2024-10-26 07:04:55

您可以通过将类 Tab 转换为 Widget 来访问选项卡样式

TabPanel tabPanel = new TabPanel();
((Widget)tabPanel().getTabBar().getTab(tabsToDisable.iterator().next())).addStyleName("disabled");

You can access tab style by casting class Tab to Widget

TabPanel tabPanel = new TabPanel();
((Widget)tabPanel().getTabBar().getTab(tabsToDisable.iterator().next())).addStyleName("disabled");
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文