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

REGRESSION: JTabbedPane with 0 tabs is drawn in TabbedPane.selected color

XMLWordPrintable

    • b34
    • x86
    • windows_2000



      Name: gm110360 Date: 08/03/2004


      FULL PRODUCT VERSION :
      java version "1.4.2_04"

      ADDITIONAL OS VERSION INFORMATION :
      Microsoft Windows 2000 [Version 5.00.2195]

      EXTRA RELEVANT SYSTEM CONFIGURATION :
      HP Compac P4 2GHz.

      A DESCRIPTION OF THE PROBLEM :
      When using Metal and explicitly setting a LaF color for the selected tab property:

      UIManager.put("TabbedPane.selected", new ColorUIResource(Color.red));

      a JTabbedPane with zero tabs is painted in the selected tab color .


      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      Run the program below under Java 1.4 and under 1.3.

      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      The JTabbedPane should be rendered in accordance with the normal LaF settings. The selected tab color should have no influence on the JTabbedPane when there are no tabs, selected or otherwise, to display.
      ACTUAL -
      Version 1.3 shows the expected behaviour. 1.4 and 1.5 beta show the incorrect colour.

      ERROR MESSAGES/STACK TRACES THAT OCCUR :
      no messages.

      REPRODUCIBILITY :
      This bug can be reproduced always.

      ---------- BEGIN SOURCE ----------
      import java.awt.*;
      import java.awt.event.*;

      import javax.swing.*;
      import javax.swing.plaf.*;

      /**
       * Shows that JTabbedPane has zero tabs, then it is drawn in the
       * TabbedPane.selected color.
       */
      public class TabSelectedBug {

          static int m_count = 0;
          
          public static void main(String args[]) {

              JFrame frame = new JFrame();
              
              //Set easy to see selected and background colors.
              UIManager.put("TabbedPane.background", new ColorUIResource(Color.blue));
              UIManager.put("TabbedPane.selected", new ColorUIResource(Color.red));
              
              frame.getContentPane().setLayout( new BorderLayout() );
              
              final JTabbedPane pane = new JTabbedPane();
              frame.getContentPane().add( pane, BorderLayout.CENTER );
              JPanel panBut = new JPanel();
              
              //Remove
              JButton butRemove = new JButton("remove");
              butRemove.addActionListener( new ActionListener() {
                  public void actionPerformed(ActionEvent e) {
                      if (pane.getTabCount() > 0 ){
                          pane.remove( pane.getSelectedIndex() );
                      }
                  }
              });
              panBut.add(butRemove);
              
              //Add
              JButton butAdd = new JButton("add");
              butAdd.addActionListener( new ActionListener() {
                  public void actionPerformed(ActionEvent e) {
                      pane.add("Panel" + ++m_count , new JPanel());
                  }
              });
              panBut.add(butAdd);
              
              frame.getContentPane().add( panBut, BorderLayout.SOUTH );
              
              frame.setSize( new Dimension(400, 300) );
              frame.setDefaultCloseOperation( JFrame.EXIT_ON_CLOSE );
              frame.show();

          }
      }

      ---------- END SOURCE ----------

      CUSTOMER SUBMITTED WORKAROUND :
      //Somthing like....
      JTabbedPanel pane;
      //...
       if (pane.getTabCount() == 0 ){
         pane.setSelectedIndex(-1);
         UIManager.setColor("TabbedPane.selected" , < appropriate laf color here>}
      }
      //and restore the selected color when pane.getTabCount() > 0

      Release Regression From : 1.3.1
      The above release value was the last known release where this
      bug was known to work. Since then there has been a regression.

      (Incident Review ID: 286888)
      ======================================================================

            alexp Alexander Potochkin (Inactive)
            gmanwanisunw Girish Manwani (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: