Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to hide tabbed panel in JTabbedPane?

Tags:

java

swing

I have:

JTabbedPane jtabbedPane = new JTabbedPane();
jTabbedPane.addTab("Tab 1", panel1);
jTabbedPane.addTab("Tab 2", panel2);
jTabbedPane.addTab("Tab 3", panel3);

What I want to do is hide Tab 2 when a condition occurs (say the user isn't permitted to access that tabbed panel.

Yes I know you can do:

jtabbedPane.setEnabled(1, false); // disable Tab 2

which will gray it out, but I want to completely hide it so that the user doesn't even know it's even a possibility in the software. They shouldn't be even aware that it exists.

I do NOT want to do

jtabbedPane.remove(1); // remove Tab 2

because I then have to remove/add on a regular basis.

like image 232
Stephane Grenier Avatar asked Oct 11 '25 14:10

Stephane Grenier


2 Answers

The only way is to remove it when you don't want to see it, and re-add it later when you do want it visible.

like image 60
Stephane Grenier Avatar answered Oct 14 '25 03:10

Stephane Grenier


This work in my project.

this.TabbedPane.setEnabledAt(1, false);
like image 22
Lucas Motta Avatar answered Oct 14 '25 02:10

Lucas Motta