如何将CTabItem隐藏在CTabFolder中

时间:2020-12-30 22:24:56

I can't find any method for making a tab invisible or otherwise hidden in an SWT/JFace application --- I want a second tab to be available (or not) based on some other preferences set by the user.

在SWT/JFace应用程序中,我找不到任何使选项卡隐形或以其他方式隐藏的方法——我希望第二个选项卡基于用户设置的其他一些首选项可用(或不可用)。

It shouldn't be so hard to figure this out!

要弄明白这一点应该不难!

1 个解决方案

#1


5  

The only way that I know of is to dispose the CTabItem for the tab you want to hide and then create a new CTabItem when you want to show it. Sort of,

我所知道的惟一方法是为要隐藏的选项卡配置CTabItem,然后在想要显示它时创建一个新的CTabItem。的,

 CTabFolder folder = new CTabFolder(parent, SWT.NONE);
 Label label = new Label(folder, SWT.NONE);
 label.setText("Hello");
 CTabItem item = new CTabItem(folder);
 item.setControl(label);
 // Hide it
 item.dipose();
 // show it again
 CTabItem item = new CTabItem(folder);
 item.setControl(label);

If you want to hide a tab in the middle you'll need to recreate all the tabs after the one you disposed.. It's probably easiest if you create a class that holds the control and a field that can be used to toggle the visibility. Then you can just dipose all the CTabItems and recreate iff the visibility field is true.

如果你想在中间隐藏一个标签,你需要重新创建所有的标签后,你处置。如果您创建了一个包含控件的类和一个可以用来切换可见性的字段,这可能是最简单的。然后您可以分解所有CTabItems并重新创建iff可见性字段为true。

#1


5  

The only way that I know of is to dispose the CTabItem for the tab you want to hide and then create a new CTabItem when you want to show it. Sort of,

我所知道的惟一方法是为要隐藏的选项卡配置CTabItem,然后在想要显示它时创建一个新的CTabItem。的,

 CTabFolder folder = new CTabFolder(parent, SWT.NONE);
 Label label = new Label(folder, SWT.NONE);
 label.setText("Hello");
 CTabItem item = new CTabItem(folder);
 item.setControl(label);
 // Hide it
 item.dipose();
 // show it again
 CTabItem item = new CTabItem(folder);
 item.setControl(label);

If you want to hide a tab in the middle you'll need to recreate all the tabs after the one you disposed.. It's probably easiest if you create a class that holds the control and a field that can be used to toggle the visibility. Then you can just dipose all the CTabItems and recreate iff the visibility field is true.

如果你想在中间隐藏一个标签,你需要重新创建所有的标签后,你处置。如果您创建了一个包含控件的类和一个可以用来切换可见性的字段,这可能是最简单的。然后您可以分解所有CTabItems并重新创建iff可见性字段为true。