Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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
like image 742
Jame Avatar asked Oct 01 '11 07:10

Jame


People also ask

How do you switch tabs in JTabbedPane by clicking a button?

You should use the method JTabbedPane. setSelectedIndex(int index) with the index of the tab you want. Show activity on this post. JTabbedpane.

Which method is used to add tabs to a JTabbedPane?

To create a tabbed pane, instantiate JTabbedPane , create the components you wish it to display, and then add the components to the tabbed pane using the addTab method.

How do you add a tab in Java?

Using \t Tab Escape Sequence Character in Java The Escape Sequence, \t is used for tab space. In other words, \t inserts a tab. We use Escape Sequence when we need to format a String . If we use \t at a specific point in a string, it will insert a new tab at that point.


1 Answers

I believe what you are looking for is this.

jTabbedPane1.setEnabledAt(n, false);
like image 191
Jordonias Avatar answered Oct 21 '22 23:10

Jordonias