MainTabSheet 组件
是一个在多标签页中显示视图的容器。一次只能选择并显示一个标签页的内容。
XML 元素 |
|
---|---|
Java 类 |
|
XML 属性 |
id - alignSelf - classNames - colspan - css - height - width - maxHeight - maxWidth - minHeight - minWidth - visible - themeNames - tabsDraggable |
事件和处理器 |
AttachEvent - DetachEvent - SelectedChangeEvent - TabsCollectionChangeEvent |
XML 内部元素 |
基本用法
在 XML 的 workArea
元素中使用 mainTabSheet
元素创建该组件。workArea
和 mainTabSheet
仅能在主视图的 XML 中使用。
下面是一个创建 mainTabSheet
的基础示例:
<mainTabSheet id="mainTabSheet"
classNames="jmix-main-tabsheet"
tabsDraggable="true"
width="100%" height="100%">
<actions>
<action id="closeThisTabAction" type="tabmod_closeThisTab"/>
<action id="closeOthersTabsAction" type="tabmod_closeOtherTabs"/>
<action id="closeAllTabsAction" type="tabmod_closeAllTabs"/>
</actions>
</mainTabSheet>
事件和处理器
SelectedChangeEvent
当用户切换标签页时,会触发 io.jmix.tabbedmode.component.workarea.TabbedViewsContainer.SelectedChangeEvent
事件。可以创建自定义的处理器,在标签页切换时执行特定逻辑。
下面的代码会在每次切换标签页时发出一个通知:
@Autowired
private Notifications notifications;
@Subscribe("mainTabSheet")
public void onMainTabSheetSelectedChange(final SelectedChangeEvent<MainTabSheet> event) {
notifications.create(event.getSelectedTab() + " is now selected")
.show();
}
如需通过 Studio 生成处理器方法的桩代码,请使用视图控制器代码顶部的 Generate Handler 按钮。或者可以在视图 XML 中选择该组件,然后在组件属性面板的 Handlers tab 生成。 |
TabsCollectionChangeEvent
当用户打开或关闭视图时,会创建新的标签页或删除已有的标签页,此时触发 io.jmix.tabbedmode.component.workarea.TabbedViewsContainer.TabsCollectionChangeEvent
事件。可以创建自定义的处理器,在标签页集合发生变化时执行特定逻辑。
下面的代码会在标签页集合发生变化时发出一个通知:
@Autowired
private Notifications notifications;
@Subscribe("mainTabSheet")
public void onMainTabSheetTabsCollectionChange(final TabsCollectionChangeEvent<MainTabSheet> event) {
notifications.create("Tabs collection changed", "Change type: " + event.getChangeType())
.show();
}
如需通过 Studio 生成处理器方法的桩代码,请使用视图控制器代码顶部的 Generate Handler 按钮。或者可以在视图 XML 中选择该组件,然后在组件属性面板的 Handlers tab 生成。 |
主题样式
centered
将标签页放置在主视图的中间位置,而不是默认的靠左排列:

small
使用小的标签页:
minimal
减少可视化样式,仅显示标签页的文本,不带任何可视化元素:
hide-scroll-buttons
隐藏标签的滚动按钮:
bordered
为标签和内容区域添加边框。