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

JTable default rowHeight is not DPI scaled

XMLWordPrintable

      FULL PRODUCT VERSION :
      java version "1.7.0_45"
      Java(TM) SE Runtime Environment (build 1.7.0_45-b18)
      Java HotSpot(TM) 64-Bit Server VM (build 24.45-b08, mixed mode)

      ADDITIONAL OS VERSION INFORMATION :
      Microsoft Windows [Version 6.1.7601]

      EXTRA RELEVANT SYSTEM CONFIGURATION :
      Retina display.
      (run on OS X 10.9 via Parallels 9)

      A DESCRIPTION OF THE PROBLEM :
      When using the Windows Look & Feel on a high DPI display, JLabel fonts and other widgets are scaled, so that they look good on the display.
      That's great.
      Unfortunately, it seems like the default JTable row height was forgotten. It is still set to 16 pixels, which is (a lot) too small and looks horrible.

       (btw, when using the standard L&F, no scaling occurs, opening up a great business opportunity for selling magnifying glasses).

      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      Run the following class on a machine with high DPI display, using DPI scaling.

      import javax.swing.*;
      import javax.swing.table.DefaultTableModel;
      import java.awt.*;

      /**
       * Demo table to demonstrate bad row height on HiDPI displays.
       */
      public class TableRowHeight {

          public static void main(String[] args) throws ClassNotFoundException, UnsupportedLookAndFeelException, InstantiationException, IllegalAccessException {
              UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
              final JFrame frame = new JFrame();
              frame.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
              final JTable table = new JTable();
              final DefaultTableModel dataModel = new DefaultTableModel(4, 1);
              dataModel.setValueAt("Some String", 0, 0);
              dataModel.setValueAt("Some String", 1, 0);
              dataModel.setValueAt("Some String", 2, 0);
              dataModel.setValueAt("Some String", 3, 0);
              table.setModel(dataModel);
              table.setAutoCreateColumnsFromModel(true);
              frame.getContentPane().setLayout(new BorderLayout());
              frame.getContentPane().add(table, BorderLayout.CENTER);
              frame.getContentPane().add(new JLabel("Label"), BorderLayout.NORTH);
              final JMenuBar menuBar = new JMenuBar();
              menuBar.add(new JMenu("Menu"));
              frame.setJMenuBar(menuBar);
              frame.setBounds(100, 100, 300, 300);
              SwingUtilities.invokeLater(new Runnable() {
                  @Override
                  public void run() {
                      frame.setVisible(true);
                  }
              });
          }

      }


      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      Using this plain vanilla approach I would expect to see a table with appropriately sized rows.
      ACTUAL -
      The rows are not high enough. Standard table content appears clipped.

      REPRODUCIBILITY :
      This bug can be reproduced always.

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

      /**
       * Demo table to demonstrate bad row height on HiDPI displays.
       */
      public class TableRowHeight {

          public static void main(String[] args) throws ClassNotFoundException, UnsupportedLookAndFeelException, InstantiationException, IllegalAccessException {
              UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
              final JFrame frame = new JFrame();
              frame.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
              final JTable table = new JTable();
              final DefaultTableModel dataModel = new DefaultTableModel(4, 1);
              dataModel.setValueAt("Some String", 0, 0);
              dataModel.setValueAt("Some String", 1, 0);
              dataModel.setValueAt("Some String", 2, 0);
              dataModel.setValueAt("Some String", 3, 0);
              table.setModel(dataModel);
              table.setAutoCreateColumnsFromModel(true);
              frame.getContentPane().setLayout(new BorderLayout());
              frame.getContentPane().add(table, BorderLayout.CENTER);
              frame.getContentPane().add(new JLabel("Label"), BorderLayout.NORTH);
              final JMenuBar menuBar = new JMenuBar();
              menuBar.add(new JMenu("Menu"));
              frame.setJMenuBar(menuBar);
              frame.setBounds(100, 100, 300, 300);
              SwingUtilities.invokeLater(new Runnable() {
                  @Override
                  public void run() {
                      frame.setVisible(true);
                  }
              });
          }

      }

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

        1. default_LaF.png
          default_LaF.png
          58 kB
        2. tablerowheight.png
          tablerowheight.png
          204 kB
        3. windows_LaF.png
          windows_LaF.png
          60 kB

            aivanov Alexey Ivanov
            serb Sergey Bylokhov
            Votes:
            0 Vote for this issue
            Watchers:
            9 Start watching this issue

              Created:
              Updated: