JDK-8213786 : Incorrect size of tooltips on scaled displays
  • Type: Bug
  • Component: client-libs
  • Sub-Component: javax.swing
  • Affected Version: 10,11,12
  • Priority: P3
  • Status: Closed
  • Resolution: Duplicate
  • OS: windows_10
  • CPU: x86_64
  • Submitted: 2018-11-12
  • Updated: 2018-11-19
  • Resolved: 2018-11-19
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 12
12Resolved
Related Reports
Duplicate :  
Description
ADDITIONAL SYSTEM INFORMATION :
Observed on Windows 7 and 10 with Java 10.0.2, 11.0.1 and 12-ea-19

A DESCRIPTION OF THE PROBLEM :
The size of tooltips are incorrect when running with font scaling (e.g. hiDPI monitors). In most cases the tooltip is too narrow, making the text go out of the right side of the tooltip. For HTML tooltips the last word is simply not shown (as it then gets painted word wrapped).

REGRESSION : Last worked in version 8u191

STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
With the Windows system look and feel (probably just because of a different font), create a component with a tooltip.

        JLabel htmlTooltipLabel = new JLabel("Label with tooltip");
        htmlTooltipLabel.setToolTipText("<html>Is there room for the last word?</html>");

Hover the component with the mouse, so a tooltip is displayed inside the window (only light weight and medium weight tooltips have the issue)

EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
The tooltip text is shown
ACTUAL -
The last word of the tooltip text is missing.

---------- BEGIN SOURCE ----------
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;

import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.SwingConstants;
import javax.swing.SwingUtilities;
import javax.swing.UIManager;
import javax.swing.WindowConstants;

public class TooltipTest extends JFrame {
    public static void main(String[] args) throws Exception {
        SwingUtilities.invokeAndWait(() -> new TooltipTest());
    }
    
    public TooltipTest() {
        try {
            UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
        }
        catch (Exception e) {
            throw new RuntimeException(e);
        }
        
        JPanel panel = new JPanel(new GridBagLayout());
        GridBagConstraints gbc = new GridBagConstraints();
        gbc.gridx = 0;
        gbc.insets.bottom = 4;
        
        String normalTooltip = "Is there room for the last word?";
        String htmlTooltip = "<html>" + normalTooltip + "</html>";
        
        JLabel normalTooltipLabel = new JLabel("Label with tooltip \"" + normalTooltip + "\"", SwingConstants.CENTER);
        normalTooltipLabel.setToolTipText(normalTooltip);
        panel.add(normalTooltipLabel, gbc);
        
        JLabel htmlTooltipLabel = new JLabel("Label with tooltip \"" + htmlTooltip + "\"", SwingConstants.CENTER);
        htmlTooltipLabel.setToolTipText(htmlTooltip);
        panel.add(htmlTooltipLabel, gbc);
        
        add(panel);
        setSize(400, 250);
        setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
        setTitle("Tooltip too short");
        setVisible(true);
    }
}

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

FREQUENCY : always



Comments
Tooltip size is incorrect when runnin with font scaling in JDK 10.0.2 and 11.0.1 and 12 ea b19. Checked this for reported versions and could confirm the issue. Results: ======== 8u191: OK 9: OK 9.0.4: OK 10: Fail 11.0.1: Fail 12 ea b19: Fail This is a regression introduced in JDK 10. To verify, run the attached test case with respective JDK version. Make sure to hover the component inside window with the mouse (see screenshots as reference).
13-11-2018