I want to customize the look of tabs in JTabbedPane.
I want to start with the simplest and simplest behavior: no borders, solid color.
The problem is that it is still unclear: the tabs are slightly overlapped by the brand.

You see that since the second tab is selected, it is “brought to the fore.” This is achieved by slightly overlapping the field. Is there a (not complicated) way to disable this behavior?
simple, verifiable (fix import only) code:
public class TabbedPane_LookStudy extends JFrame{ public static void main(String [] args) throws UnsupportedLookAndFeelException { UIManager.setLookAndFeel(new NimbusLookAndFeel()); new TabbedPane_LookStudy().setVisible(true); } public TabbedPane_LookStudy() { JTabbedPane tp = new JTabbedPane(); tp.setUI(new MyTabbedPaneUI()); add(tp); tp.addTab("first",new JPanel()); tp.addTab("second", new JPanel()); tp.addTab("third", new JPanel()); setPreferredSize(new Dimension(180,100)); pack(); } public static class MyTabbedPaneUI extends javax.swing.plaf.basic.BasicTabbedPaneUI { @Override protected void paintTab(Graphics g, int tabPlacement, Rectangle[] rects, int tabIndex, Rectangle iconRect, Rectangle textRect) { Color savedColor = g.getColor(); g.setColor(Color.PINK); g.fillRect(rects[tabIndex].x, rects[tabIndex].y, rects[tabIndex].width, rects[tabIndex].height); g.setColor(Color.BLUE); g.drawRect(rects[tabIndex].x, rects[tabIndex].y, rects[tabIndex].width, rects[tabIndex].height); g.setColor(savedColor); } }
}
java swing jtabbedpane
Agostinox
source share