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

Incorrect size of tooltips on scaled displays

XMLWordPrintable

    • 10
    • x86_64
    • windows_10

      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


            psadhukhan Prasanta Sadhukhan
            webbuggrp Webbug Group
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

              Created:
              Updated:
              Resolved: