Java – JTabbedPane: Components before and after the tabs themselves

google-chromejavajtabbedpaneuser interface

This is similar to the question How to build a Google-chrome tabs and menubar interface in Java Swing? (I want to accomplish the same), but more to the point: How do I put components in front and behind the tabs in a JTabbedPane?

I've already come up with the buttons-idea myself, but I'd rather have a JTabbedPane, since that is really what it is, but decorated with a button or icons on the sides.

I've seen that the laf-widget project from Kirill does something like it (the magnifying-glass icon to the left of the tabs) for several LaFs. However, I must admit that I'm not yet well enough versed to understand how he does it – and also it seems like a somewhat complicated process, whereby one "physically" change the LaF in question (bytecode manipulates it), injecting the laf-widget stuff into the UI delegates – and I still don't know how the JTabbedPane or TabbedPaneUI is actually modulated to inject that icon/button.

Best Answer

I finally asked Kirill of Substance LaF/laf-widget of how he manages to put a button in front of the tabs in the laf-widget that decorates JTabbedPanes, and this is his reply:

It relies on the BasicTabbedPaneUI.tabAreaInsets field to make room for the button, and custom setBounds of the button component to position itself in that area.

For more code, see TabOverviewButton and TabOverviewDialogWidget classes in the laf-widget project.

In general, the tabbed pane UI delegate is one of the least attractive ones to enhance since it has a lot of private and package protected methods

Thanks, Kirill!