// -*- mode:java; encoding:utf-8 -*-
// vim:set fileencoding=utf-8:
// @homepage@

package example;

import com.sun.java.swing.plaf.windows.WindowsTabbedPaneUI;
import java.awt.*;
import javax.swing.*;
import javax.swing.plaf.basic.BasicTabbedPaneUI;

public final class MainPanel extends JPanel {
  private MainPanel() {
    super(new BorderLayout());
    UIManager.put("TabbedPane.tabInsets", new Insets(1, 4, 0, 4));
    UIManager.put("TabbedPane.selectedTabPadInsets", new Insets(1, 1, 1, 1));
    UIManager.put("TabbedPane.tabAreaInsets", new Insets(3, 2, 0, 2));
    UIManager.put("TabbedPane.selectedLabelShift", 0);
    UIManager.put("TabbedPane.labelShift", 0);

    JTabbedPane tabs = new UnderlineFocusTabbedPane();
    tabs.addTab("JTree", new ColorIcon(Color.RED), new JScrollPane(new JTree()));
    tabs.addTab("JTextArea", new ColorIcon(Color.GREEN), new JScrollPane(new JTextArea()));
    tabs.addTab("JTable", new ColorIcon(Color.BLUE), new JScrollPane(new JTable(8, 3)));
    tabs.addTab("JSplitPane", new ColorIcon(Color.ORANGE), new JScrollPane(new JSplitPane()));
    tabs.setSelectedIndex(-1);
    EventQueue.invokeLater(() -> tabs.setSelectedIndex(0));

    add(tabs);
    setPreferredSize(new Dimension(320, 240));
  }

  public static void main(String[] args) {
    EventQueue.invokeLater(MainPanel::createAndShowGui);
  }

  private static void createAndShowGui() {
    try {
      UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
    } catch (ClassNotFoundException | InstantiationException | IllegalAccessException | UnsupportedLookAndFeelException ex) {
      ex.printStackTrace();
      Toolkit.getDefaultToolkit().beep();
    }
    JFrame frame = new JFrame("@title@");
    frame.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
    frame.getContentPane().add(new MainPanel());
    frame.pack();
    frame.setLocationRelativeTo(null);
    frame.setVisible(true);
  }
}

class UnderlineFocusTabbedPane extends JTabbedPane {
  private static final Color ALPHA_ZERO = new Color(0x0, true);
  private static final Color SELECTION_COLOR = new Color(0x00_AA_FF);

  protected UnderlineFocusTabbedPane() {
    super();
  }

  @Override public void updateUI() {
    super.updateUI();
    // setFocusable(false);
    if (getUI() instanceof WindowsTabbedPaneUI) {
      setUI(new WindowsTabbedPaneUI() {
        @Override protected void paintFocusIndicator(Graphics g, int tabPlacement, Rectangle[] rects, int tabIndex, Rectangle iconRect, Rectangle textRect, boolean isSelected) {
          super.paintFocusIndicator(g, tabPlacement, rects, tabIndex, iconRect, textRect, false);
        }
      });
    } else {
      setUI(new BasicTabbedPaneUI() {
        @Override protected void paintFocusIndicator(Graphics g, int tabPlacement, Rectangle[] rects, int tabIndex, Rectangle iconRect, Rectangle textRect, boolean isSelected) {
          super.paintFocusIndicator(g, tabPlacement, rects, tabIndex, iconRect, textRect, false);
        }
      });
    }
    addChangeListener(e -> {
      JTabbedPane tabbedPane = (JTabbedPane) e.getSource();
      if (tabbedPane.getTabCount() <= 0) {
        return;
      }
      int idx = tabbedPane.getSelectedIndex();
      for (int i = 0; i < tabbedPane.getTabCount(); i++) {
        Component c = tabbedPane.getTabComponentAt(i);
        if (c instanceof JComponent) {
          Color color = i == idx ? SELECTION_COLOR : ALPHA_ZERO;
          ((JComponent) c).setBorder(BorderFactory.createMatteBorder(0, 0, 3, 0, color));
        }
      }
    });
  }

  @Override public void insertTab(String title, Icon icon, Component component, String tip, int index) {
    super.insertTab(title, icon, component, tip, index);
    JLabel label = new JLabel(title, icon, SwingConstants.CENTER);
    setTabComponentAt(index, label);
  }
}

class ColorIcon implements Icon {
  private final Color color;

  protected ColorIcon(Color color) {
    this.color = color;
  }

  @Override public void paintIcon(Component c, Graphics g, int x, int y) {
    Graphics2D g2 = (Graphics2D) g.create();
    g2.translate(x, y);
    g2.setPaint(color);
    g2.fillRect(1, 1, getIconWidth() - 3, getIconHeight() - 3);
    g2.dispose();
  }

  @Override public int getIconWidth() {
    return 16;
  }

  @Override public int getIconHeight() {
    return 16;
  }
}

@@ -105,149 +105,40 @@
 ort 
-com.sun.java.swing.plaf.windows.WindowsTabbedPaneUI;%0Aimport java.awt.*;%0Aimport javax.swing.*;%0Aimport javax.swing.plaf.basic.BasicTabbedPaneUI
+java.awt.*;%0Aimport javax.swing.*
 ;%0A%0Ap
@@ -2105,57 +2105,93 @@
     
-super.updateUI();%0A    // setFocusable(false
+UIManager.put(%22TabbedPane.focus%22, new Color(0x0, true));%0A    super.updateUI(
 );%0A   
+ //
  if 
@@ -2232,24 +2232,27 @@
 aneUI) %7B%0A   
+ //
    setUI(new
@@ -2271,32 +2271,35 @@
 edPaneUI() %7B%0A   
+ //
      @Override p
@@ -2452,32 +2452,35 @@
 sSelected) %7B%0A   
+ //
        super.pai
@@ -2488,32 +2488,50 @@
 tFocusIndicator(
+%0A    //           
 g, tabPlacement,
@@ -2571,32 +2571,35 @@
 ect, false);%0A   
+ //
      %7D%0A      %7D);
@@ -2584,32 +2584,35 @@
     //     %7D%0A   
+ //
    %7D);%0A    %7D els
@@ -2605,16 +2605,19 @@
  %7D);%0A   
+ //
  %7D else 
@@ -2621,16 +2621,19 @@
 se %7B%0A   
+ //
    setUI
@@ -2658,24 +2658,27 @@
 neUI() %7B%0A   
+ //
      @Overri
@@ -2839,24 +2839,27 @@
 ected) %7B%0A   
+ //
        super
@@ -2879,16 +2879,34 @@
 dicator(
+%0A    //           
 g, tabPl
@@ -2958,24 +2958,27 @@
  false);%0A   
+ //
      %7D%0A     
@@ -2976,25 +2976,31 @@
   %7D%0A    
+//
   
+ 
 %7D);%0A   
+ //
  %7D%0A    a

use classes from the Java API instead of Sun classes