JDK-8029087 : JTable default rowHeight is not DPI scaled
  • Type: Bug
  • Component: client-libs
  • Sub-Component: javax.swing
  • Affected Version: 7u4,8
  • Priority: P3
  • Status: Open
  • Resolution: Unresolved
  • OS: windows_7
  • Submitted: 2013-11-22
  • Updated: 2018-12-24
The Version table provides details related to the release that this issue/RFE will be addressed.

Unresolved : Release in which this issue/RFE will be addressed.
Resolved: Release in which this issue/RFE has been resolved.
Fixed : Release in which this issue/RFE has been fixed. The release containing this fix may be available for download as an Early Access Release or a General Availability Release.

To download the current JDK release, click here.
JDK 8
8-poolUnresolved
Related Reports
Relates :  
Description
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 ----------
Comments
Yep���"cannot reproduce" is certainly the wrong tag, as the bug was reported against JDK 7 and 8 on Windows 7, not JDK12 on Windows 10. "will not fixed" is more appropriate, if that's the decision on this.
06-09-2018

For completeness sake: Which OS and JDK did you use when you've tried to reproduce? (thanks for editing your comment and including the missing info)
06-09-2018

That's pretty much expected: JDK 9 and later has full support for High DPI displays. It's likely still an issue for JDK 7 and 8.
06-09-2018

Attached screenshot tablerowheight.png tested on windows 10 with jdk12 seems to show JTable row height is suitably scaled when I ran the program with uiScale 2.0 with Windows L&F. Also tried with Metal, Nimbus and Motif and there also the row height are scaled properly.
06-09-2018

> We need to decide how to process hidpi on windows in general. Like on osx or like native windows applications or somehow? I'm under the impression that that is all figured out by now and perhaps it is time to re-visit this bug again. More and more people running Windows are moving to HiDPI/4k displays and Swing apps don't look the best they can (last time I checked).
14-01-2016

Release team: Approved for deferral.
25-11-2013

8-defer-request: This mode isn't completely supported now, not a regression.
25-11-2013

We need to decide how to process hidpi on windows in general. Like on osx or like native windows applications or somehow?
25-11-2013

On second thought, perhaps the 16 pixels Table.rowHeight is the correct approach. And scaling up fonts to be a lot larger (as it happens in Win L&F) is what's wrong. Because it violates write once, run anywhere. On OS X you guys have been struggling to implement MultiResolutionImages and the like, so that if the physical display resolution is high, Java can automatically render a high resolution version of a given image. In the same spirit the L&F font sizes aren't suddenly changed, but instead they are rendered with greater detail. Because we use a virtual desktop resolution. Now, if on Windows with Windows L&F suddenly all fonts are a lot larger, but images are still the same size (status quo) and in relation to labels way too small, things look out of proportion, layouts are broken. The OS X solution allows for seamless migration, even if the programmer does not supply MultiResolutionImages. The current (1.7.0_45) Windows L&F does not allow this. And regardless which approach is better: Shouldn't both L&Fs use the same approach?! If you agree and have access to the Oracle bug database, please add this opinion as a comment (Oracle bug id 9008405). Or better���talk to the guys in charge of Windows L&F. Thanks, -hendrik
25-11-2013

jdk8: SQE OK to defer
25-11-2013