java NetBeans:如何在 JTabedPane 中启用/禁用特定选项卡

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/7618749/
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-30 20:43:02  来源:igfitidea点击:

NetBeans: How to enable/disable specific tab in JTabedPane

javaswingnetbeansjtabbedpane

提问by Jame

I am developing a small desktop application in Netbeans. on my UI i have a JTabbedPanehaving 3 tabs in it now i come across a situation where i need to temporarily disable 2nd and 3rd tab. How could i do that programatically. Rightnow i am using the following code but its not working:

我正在 Netbeans 中开发一个小型桌面应用程序。在我的用户界面上,我有JTabbedPane3 个选项卡,现在我遇到了需要暂时禁用第二个和第三个选项卡的情况。我怎么能以编程方式做到这一点。现在我正在使用以下代码,但它不起作用:

int n = jTabbedPane1.indexOfTab("Second Tab Name");// This line returns one as expected
jTabbedPane1.getTabComponentAt(n).enable(false);// but i guess some un-expected thing happens here

回答by Jordonias

I believe what you are looking for is this.

我相信你正在寻找的是这个。

jTabbedPane1.setEnabledAt(n, false);

回答by Miki Maine Amdu

you can simply use

你可以简单地使用

 tabObject.setEnabledAt(index, enabled);

tabObject :- is the JTabbedPane index would start from 0.So,you Should use 1 and 2 for the second and third tabs enabled is the Boolean value true for on and false for off. i think it helps

tabObject :- 是 JTabbedPane 索引将从 0 开始。所以,你应该为第二个和第三个选项卡使用 1 和 2 启用是布尔值 true 表示开,false 表示关闭。我认为它有帮助