NetBeans: How to enable/disable specific tab in JTabedPane

时光总嘲笑我的痴心妄想 提交于 2020-03-13 04:09:51

问题


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

回答1:


I believe what you are looking for is this.

jTabbedPane1.setEnabledAt(n, false);



回答2:


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



来源:https://stackoverflow.com/questions/7618749/netbeans-how-to-enable-disable-specific-tab-in-jtabedpane

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!