JTabbedPane Transparency

Hello,
I am trying to make a JTabbedPane have transparency.

Here is the setup
JFrame->JPanel->JTabbedPane -> JPanel

I call the setOpaque method to false on the JTabbedPane and the JPanel that it contains.
The root JPanel does not show through the TabbedPane - its just a light blue.

Anyone have any hints?

Thanks

I did some experimenting and it looks like you have to make your own TabbedPaneUI. I first tried the following as I might suspect you did as well:


// didn't change much even though I thought it would 
tabbed.setOpaque(false);
tabbed.putClientProperty("TabbedPane.contentOpaque", Boolean.FALSE);
tabbed.putClientProperty("TabbedPane.tabsOpaque", Boolean.FALSE);

Then I tried to create my own TabbedPaneUI) inheriting BasicTabbedPaneUI


MyTabbedPaneUI ui = new MyTabbedPaneUI();
tabbed.setUI(ui);

It was very easy to make the actual tab area transparent but it was more difficult to make the content area so. It seems that UI is using more components to create the internal parts. I didn’t manage to solve the issue entirely but it is solvable if you have the time to create your own TabbedPaneUI.

Peter

Yes, and the same applies to the JScrollPane as well…

I’ve resorted to making my own class called TransparentTabbedPane. This gives me actaully what I want.

I used 2 JPanels - one holds the menus and the other holds the component associated with the tab. I use a BorderLayout to position the menu and data panel. I dynamically position the tabs based on the size of the window and the number of tabs. Each tab is an Object that contains a JButton. When you click on the tab, I disable the button. When another button is clicked on, then the disabled button must be re-enabled and then the new button disabled. Events are handled with an Action Listener.

Here is a screen shot of my tabs in action (note, I actually have 2 TabbedPanes - one controlling the top row and another the second row ).

Looks good. How about using JRadioButtons and a ButtonGroup so you dont need to keep track of the deactivation bit. :slight_smile:

Peter

Thats a good idea and wish I would have thought of it; unfortunatly, I already have that coded. Next though, next time.