简体   繁体   中英

NetBeans: How to enable/disable specific tab in JTabedPane

I am developing a small desktop application in 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. 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. i think it helps

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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