java 从 JTabbedPane 隐藏选项卡

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/14003796/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-31 14:42:43  来源:igfitidea点击:

Hide tab from JTabbedPane

javaswingjtabbedpane

提问by Favolas

I'm using Netbeans gui to create a simple app.

我正在使用 Netbeans gui 创建一个简单的应用程序。

This is my structure (the layout is free design):

这是我的结构(布局是免费设计的):

enter image description here

在此处输入图片说明

Basically I have 3 tabs and want to hide one of them (the select one in the image) based on a condition. Something like if the user as some privileges show that tab, otherwise don't show that tab.

基本上我有 3 个选项卡,想根据条件隐藏其中一个(图像中的选择一个)。就像用户作为某些权限显示该选项卡一样,否则不显示该选项卡。

On my code I've tried;

在我尝试过的代码上;

 if (userRole == 1){
    pnlAdiconarSala.setVisible(false);
 }

but this tab is always showing.

但此选项卡始终显示。

With my implementation, can I hide the tab?

通过我的实现,我可以隐藏选项卡吗?

回答by j2gl

Short answer:

简答:

if (userRole == 1){
   tbpGeral.remove(pnlAdiconarSala)
}