Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-6815439

Removing a null tab may disorganize titles with htlm content.

XMLWordPrintable

      JTabbedPane supports tab with null component, however it treats it in a special way.
      Swing doesn't allow null component to be added, so the usual machinery with
      ContainerListener.componentAdded/componentRemoved doesn't work.

      It leads to a situation when html views vector goes unsynchronized when a tab with a null component is removed, so you can see html tags in the tab's title
      instead of real html formatting.

      import javax.swing.*;

      public class MyTest {

          private static void createGui() {
              final JFrame frame = new JFrame();
              frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
              
              JTabbedPane pane = new JTabbedPane();
              pane.addTab("Hello", null, null);
              
              // This line would work
      // pane.addTab("Hello", null, new JPanel());
              pane.addTab("<html><u>underlined text</u></html>", null, null);
              pane.removeTabAt(0);
              frame.add(pane);

              frame.setSize(200, 200);
              frame.setLocationRelativeTo(null);
              frame.setVisible(true);
          }

          public static void main(String[] args) throws Exception {
              SwingUtilities.invokeAndWait(new Runnable() {
                  public void run() {
                      MyTest.createGui();
                  }
              });
          }
      }

            Unassigned Unassigned
            alexp Alexander Potochkin (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Created:
              Updated:
              Imported:
              Indexed: