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

Wrong placement of icons in JTabbedPane in Nimbus

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Fixed
    • Icon: P3 P3
    • 22
    • 6u16
    • client-libs
    • b06
    • x86
    • windows_xp

      java version "1.6.0_16"
      Java(TM) SE Runtime Environment (build 1.6.0_16-b01)
      Java HotSpot(TM) Client VM (build 14.2-b01, mixed mode, sharing)

      Does this problem occur on J2SE 5.0.x or 6.0? Yes / No (pick one)
      Yes

      Operating System Configuration Information (be specific):
      Client: Microsoft Windows XP [Version 5.1.2600]

      Bug Description:
      Different Look and Feels are not following the JTabbedPane's JavaDoc

      Tested the 5 Look and Feels installed by uncommenting each of them one by one.

      Here are the results:
      Metal: The selected tab is not using the specified background
             (foreground, unselected tab backgrounds and icons are fine)

      Nimbus: No tabs are using the specified background, or the specified
              foreground and the icons are placed in strange locations

      Motif: The unselected tabs are not using the specified background
             (foreground, selected tab background and icons are fine)

      Windows: No tabs are using the specified background
              (foreground and icons are fine)

      Window Classic: (background, foreground and icons are all fine)

      As can be seen all 5 look and feels do 5 different things making it very difficult
      to use the JTabbedPane so that it looks ok using all 5 Look and Feels.

      Nimbus is by far the worst.

      import static java.awt.Color.*;
      import static javax.swing.JFrame.*;
      import java.awt.*;
      import javax.swing.*;

      public class Test {
        private static void addTab(JTabbedPane aTabbedPane, int anIndex) {
          aTabbedPane.addTab("Tab " + anIndex, new Icon() {
            @Override
            public void paintIcon(Component aComponent, Graphics aGraphics, int anX, int aY) {
              aGraphics.setColor(BLUE);
              aGraphics.fillOval(anX, aY, 8, 8);
            }

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

            @Override
            public int getIconHeight() {
              return 8;
            }
          }, new JLabel("Component " + anIndex));
          aTabbedPane.setForegroundAt(anIndex, RED);
          aTabbedPane.setBackgroundAt(anIndex, YELLOW);
        }

        public static void main(String[] args) throws Exception {
          // UIManager.setLookAndFeel("javax.swing.plaf.metal.MetalLookAndFeel");
          UIManager.setLookAndFeel("com.sun.java.swing.plaf.nimbus.NimbusLookAndFeel");
          // UIManager.setLookAndFeel("com.sun.java.swing.plaf.motif.MotifLookAndFeel");
          // UIManager.setLookAndFeel("com.sun.java.swing.plaf.windows.WindowsLookAndFeel");
          // UIManager.setLookAndFeel("com.sun.java.swing.plaf.windows.WindowsClassicLookAndFeel");
          JTabbedPane tabbedPane = new JTabbedPane();
          for (int i = 0; i < 5; i++) {
            addTab(tabbedPane, i);
          }
          JFrame frame = new JFrame();
          frame.add(tabbedPane);
          frame.setSize(500, 500);
          frame.setDefaultCloseOperation(EXIT_ON_CLOSE);
          frame.setVisible(true);
        }
      }

            psadhukhan Prasanta Sadhukhan
            tyao Ting-Yun Ingrid Yao (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: