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

Setting default font size for JTabbedPane in Nimbus causes erratic drawing

XMLWordPrintable

      FULL PRODUCT VERSION :
      java version "1.6.0_10-beta"
      Java(TM) SE Runtime Environment (build 1.6.0_10-beta-b23)
      Java HotSpot(TM) Client VM (build 11.0-b11, mixed mode, sharing)

      ADDITIONAL OS VERSION INFORMATION :
      Windows XP

      A DESCRIPTION OF THE PROBLEM :
      Trying to set the default font size of tab text in a JTabbedPane via the UIDefaults causes text to extend outside the bounds of the tab. Also, tabs erratically resize when adjusting the size of the window and the selected tab has a smaller font than the non-selected tabs.


      REPRODUCIBILITY :
      This bug can be reproduced always.

      ---------- BEGIN SOURCE ----------
      import java.awt.BorderLayout;
      import java.awt.Font;
      import java.awt.GridBagLayout;

      import javax.swing.JFrame;
      import javax.swing.JPanel;
      import javax.swing.JTabbedPane;
      import javax.swing.UIDefaults;
      import javax.swing.UIManager;
      import javax.swing.plaf.FontUIResource;

      public class TabsFrame extends JFrame {

          public static void main(String args[]) {
              try {
                  UIManager.setLookAndFeel("com.sun.java.swing.plaf.nimbus.NimbusLookAndFeel");
                  UIDefaults defaults = UIManager.getLookAndFeelDefaults();
                  Font font = defaults.getFont("TabbedPane.font");
                  font = font.deriveFont(16f);
                  defaults.put("TabbedPane.font", new FontUIResource(font));

                  TabsFrame frame = new TabsFrame();
                  frame.setVisible(true);
              }
              catch(Exception e) {
                  e.printStackTrace();
              }
          }

          /**
           * Create the frame
           */
          public TabsFrame() {
              setBounds(100, 100, 500, 375);
              setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

              final JTabbedPane tabbedPane = new JTabbedPane();
              getContentPane().add(tabbedPane, BorderLayout.CENTER);

              final JPanel panel = new JPanel();
              panel.setLayout(new BorderLayout());
              tabbedPane.addTab("This is a tab", null, panel, null);

              final JPanel panel_1 = new JPanel();
              panel_1.setLayout(new GridBagLayout());
              tabbedPane.addTab("Tab2", null, panel_1, null);

              final JPanel panel_2 = new JPanel();
              tabbedPane.addTab("This will be tab 3", null, panel_2, null);
          }
      }

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

      CUSTOMER SUBMITTED WORKAROUND :
      Set the font of each individal JTabbedPane instead of using the UIDefaults to set all JTabbedPane instances.

            peterz Peter Zhelezniakov
            ndcosta Nelson Dcosta (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Imported:
              Indexed: