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

package example;

import java.awt.*;
import javax.swing.*;

public final class MainPanel extends JPanel {
  private int count;

  private MainPanel() {
    super(new BorderLayout());

    JTabbedPane tabs = new JTabbedPane() {
      @Override public void addTab(String title, Component content) {
        super.addTab(title, content);
        // // TEST:
        // JCheckBox check = new JCheckBox(title) {
        //   private final Rectangle viewRect = new Rectangle();
        //   private final Rectangle textRect = new Rectangle();
        //   private final Rectangle iconRect = new Rectangle();
        //   @Override public boolean contains(int x, int y) {
        //     Icon icon;
        //     ButtonUI ui = getUI();
        //     if (ui instanceof BasicRadioButtonUI) {
        //       icon = ((BasicRadioButtonUI) ui).getDefaultIcon();
        //     } else if (ui instanceof SynthButtonUI) {
        //       // icon = ((SynthButtonUI) ui).getDefaultIcon(this);
        //       SynthContext context = ((SynthButtonUI) ui).getContext(this);
        //       icon = context.getStyle().getIcon(context, "CheckBox.icon");
        //       // context.dispose();
        //     } else {
        //       icon = getIcon();
        //     }
        //     if (Objects.nonNull(icon)) {
        //       // layout the text and icon
        //       int width = getWidth();
        //       int height = getHeight();
        //       FontMetrics fm = getFontMetrics(getFont());
        //       Insets i = getInsets();
        //       viewRect.setBounds(i.left, i.top, width - i.right - i.left, height - i.bottom - i.top);
        //       textRect.setBounds(0, 0, 0, 0);
        //       iconRect.setBounds(0, 0, 0, 0);
        //       SwingUtilities.layoutCompoundLabel(
        //         this, fm, getText(), icon,
        //         getVerticalAlignment(), getHorizontalAlignment(),
        //         getVerticalTextPosition(), getHorizontalTextPosition(),
        //         viewRect, iconRect, textRect,
        //         getIconTextGap());
        //       return iconRect.contains(x, y);
        //     } else {
        //       return super.contains(x, y);
        //     }
        //   }
        //   @Override public void updateUI() {
        //     super.updateUI();
        //     setOpaque(false);
        //     setFocusable(false);
        //   }
        // };
        // setTabComponentAt(getTabCount() - 1, check);
        JCheckBox check = new JCheckBox();
        check.setOpaque(false);
        check.setFocusable(false);
        JPanel p = new JPanel(new FlowLayout(FlowLayout.LEADING, 0, 0));
        p.setOpaque(false);
        p.add(check, BorderLayout.WEST);
        p.add(new JLabel(title));
        setTabComponentAt(getTabCount() - 1, p);
      }
    };
    tabs.addTab("JTree", new JScrollPane(new JTree()));
    tabs.addTab("JLabel", new JLabel("aaaaaaaaaaaaa"));

    JButton button = new JButton("Add");
    button.addActionListener(e -> addTab(tabs));

    add(tabs);
    add(button, BorderLayout.SOUTH);
    setPreferredSize(new Dimension(320, 240));
  }

  public void addTab(JTabbedPane tabs) {
    Component c = count % 2 == 0 ? new JTree() : new JLabel("Tab" + count);
    tabs.addTab("Title" + count, c);
    tabs.setSelectedIndex(tabs.getTabCount() - 1);
    count++;
  }

  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);
  }
}

@@ -113,16 +113,66 @@
 .awt.*;%0A
+import java.util.concurrent.atomic.AtomicInteger;%0A
 import j
@@ -185,16 +185,16 @@
 wing.*;%0A
-
 %0Apublic 
@@ -236,30 +236,8 @@
 l %7B%0A
-  private int count;%0A%0A
   pr
@@ -252,24 +252,24 @@
 inPanel() %7B%0A
+
     super(ne
@@ -283,25 +283,24 @@
 rLayout());%0A
-%0A
     JTabbedP
@@ -2305,32 +2305,43 @@
 %0A        //   %7D%0A
+        //%0A
         //   @Ov
@@ -2661,32 +2661,33 @@
 cusable(false);%0A
+%0A
         JPanel p
@@ -3008,26 +3008,69 @@
 el(%22
-aaaaaaaaaaaaa%22));%0A
+JLabel%22));%0A%0A    AtomicInteger counter = new AtomicInteger(0);
 %0A   
@@ -3145,169 +3145,53 @@
  -%3E 
-addTab(tabs));%0A%0A    add(tabs);%0A    add(button, BorderLayout.SOUTH);%0A    setPreferredSize(new Dimension(320, 240));%0A  %7D%0A%0A  public void addTab(JTabbedPane tabs) %7B%0A
+%7B%0A      int i = counter.getAndIncrement();%0A  
     
@@ -3204,17 +3204,15 @@
 ent 
-c = count
+tab = i
  %25 2
@@ -3249,27 +3249,30 @@
 el(%22
-Tab%22 + count
+JLabel: %22 + i
 );%0A    
+  
 tabs
@@ -3285,27 +3285,25 @@
 b(%22T
-itle%22 + count, c
+ab%22 + i, tab
 );%0A
+  
     
@@ -3357,15 +3357,110 @@
     
-count++
+%7D);%0A%0A    add(tabs);%0A    add(button, BorderLayout.SOUTH);%0A    setPreferredSize(new Dimension(320, 240))
 ;%0A  

use AtomicInteger instead of int for counter