简体   繁体   中英

Overlapping tabs with JTabbedPane

Using JTabbedPane we want to implement a design that requires tabs to be overlapping (illustrated in image that can be found here: http://imm.io/YAZ ).

Not exactly rocket science, but I can't seem to find a solution (not even after extensive googling).

Is this possible using JTabbedPane (via PLAF maybe) or do we need to write a custom component?

Thanks
Tomas

As far as I know it requires a custom component. I think it can be done by extending the JTabbedPane and inserting a new type of tab.

The way you make it overlap is by calling the paintComponent method on the selected tab last ie it will be closest to the front of the view.

As for the overlapping tab class you can make use of almost any JComponent subclass for your code. You can even theme it with transparent PNG's as background and calling public void setOpaque(boolean isOpaque) on the tab itself.

Solved this by overriding paintTab in a custom UI implementation and painting part of the previous tab over the next. This was possible since paintTab allows you to paint over the entire tab area, not solely in the bounds of the tab it was currently painting. Example, if we have tabs A, B and C:

Tab A paints its left border and center fill. Tab B paints its left border, center fill and then tab A's right border. Tab C paints its left border, center fill, Tab B's right border and then it's own right border (since this is the last tab in the pane).

Then handle selected tabs slightly differently.

The above solution was not hard to implement and works very well.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM