Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Hide tab from JTabbedPane

I'm using Netbeans gui to create a simple app.

This is my structure (the layout is free design ):

enter image description here

Basically I have 3 tabs and want to hide one of them (the select one in the image) based on a condition. Something like if the user as some privileges show that tab, otherwise don't show that tab.

On my code I've tried;

 if (userRole == 1){
    pnlAdiconarSala.setVisible(false);
 }

but this tab is always showing.

With my implementation, can I hide the tab?

like image 564
Favolas Avatar asked Dec 22 '12 14:12

Favolas


People also ask

How do I add a tab to 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.

What is displayed by JTabbedPane?

A JTabbedPane contains a tab that can have a tool tip and a mnemonic, and it can display both text and an image. The shape of a tab and the way in which the selected tab is displayed varies by Look and Feel.


2 Answers

Here is an clean example

  1. How to Use Tabbed Panes
  2. Inserting, Removing, Finding, and Selecting Tabs
like image 54
vels4j Avatar answered Sep 21 '22 13:09

vels4j


Short answer:

if (userRole == 1){
   tbpGeral.remove(pnlAdiconarSala)
}
like image 24
j2gl Avatar answered Sep 23 '22 13:09

j2gl