简体   繁体   English

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

[英]NetBeans: How to enable/disable specific tab in JTabedPane

I am developing a small desktop application in Netbeans.我正在 Netbeans 中开发一个小型桌面应用程序。 on my UI i have a JTabbedPane having 3 tabs in it now i come across a situation where i need to temporarily disable 2nd and 3rd tab.在我的 UI 上,我有一个JTabbedPane有 3 个选项卡,现在我遇到了需要暂时禁用第二个和第三个选项卡的情况。 How could i do that programatically.我怎么能以编程方式做到这一点。 Rightnow i am using the following code but its not working:现在我正在使用以下代码,但它不起作用:

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

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

jTabbedPane1.setEnabledAt(n, false);

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM