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

JTabbedPane LAFs should respect the Background Color in the Content Area

XMLWordPrintable

      FULL PRODUCT VERSION :
      Java(TM) SE Runtime Environment (build 1.6.0-rc-b95)


      A DESCRIPTION OF THE PROBLEM :
      The LAFS, which are responsible for painting the background content area of a JTabbedPane should respect the color set on the background of the widget. I see this behavior in these UIs:
      1. Metal: uses UI color
      2. Motif: respects background color
      3. GTK: uses UI color
      4. Windows, unknown untested

      This code in BasicTabbedPaneUI shows the coloring priorities:
                  Color color = UIManager.getColor("TabbedPane.contentAreaColor");
                  if (color != null) {
                      g.setColor(color);
                  }
                  else if ( selectedColor == null || selectedIndex == -1 ) {
                      g.setColor(tabPane.getBackground());
                  }
                  else {
                      g.setColor(selectedColor);
                  }

      The ui color comes first then the selected color. I would think the true order would be:
      1. Selected color
      2. Background color
      3. UI color

      #1 could be #2 in this list, Im assuming that there is a way to set the color.

      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      Run this code, try with different LAFs see which ones result in a green background color:
      import javax.swing.*;
      import java.awt.*;

      public class BackgroundJTabbedPane implements Runnable{

          public void run(){

              JTabbedPane jtp = new JTabbedPane();
              jtp.setBackground(Color.green);
              for(int i = 0; i < 10; i ++){
                  JPanel jp = new JPanel();
                  jp.setOpaque(false);
                  JButton jb = new JButton(String.valueOf(i));
                  jp.add(jb);
                  jtp.addTab(String.valueOf(i), jp);
              }

              JFrame jf = new JFrame();
              jf.add(jtp);
              jf.setSize(500,500);
              jf.setVisible(true);
          }



          public static void main(String ... args){
              try{
      int i = Integer.parseInt(args[0]);
                  if(i == 0) UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
                  else if(i == 1) UIManager.setLookAndFeel("com.sun.java.swing.plaf.motif.MotifLookAndFeel");

              }
              catch(Exception x){}
              SwingUtilities.invokeLater(new BackgroundJTabbedPane());
          }



      }

      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      a nice green background
      ACTUAL -
      dependant upon LAF, motif is the only one with a nice green background

      REPRODUCIBILITY :
      This bug can be reproduced always.

      ---------- BEGIN SOURCE ----------
      import javax.swing.*;
      import java.awt.*;

      public class BackgroundJTabbedPane implements Runnable{

          public void run(){

              JTabbedPane jtp = new JTabbedPane();
              jtp.setBackground(Color.green);
              for(int i = 0; i < 10; i ++){
                  JPanel jp = new JPanel();
                  jp.setOpaque(false);
                  JButton jb = new JButton(String.valueOf(i));
                  jp.add(jb);
                  jtp.addTab(String.valueOf(i), jp);
              }

              JFrame jf = new JFrame();
              jf.add(jtp);
              jf.setSize(500,500);
              jf.setVisible(true);
          }



          public static void main(String ... args){
              try{
      int i = Integer.parseInt(args[0]);
                  if(i == 0) UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
                  else if(i == 1) UIManager.setLookAndFeel("com.sun.java.swing.plaf.motif.MotifLookAndFeel");

              }
              catch(Exception x){}
              SwingUtilities.invokeLater(new BackgroundJTabbedPane());
          }



      }
      ---------- END SOURCE ----------

            alexp Alexander Potochkin (Inactive)
            ndcosta Nelson Dcosta (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: