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

Tooltips Are Distorted When Frame Is Fullscreen on a HiDPI Display

XMLWordPrintable

    • 2d
    • x86_64
    • os_x

      ADDITIONAL SYSTEM INFORMATION :
      MacBook Pro M1 Max with macOS 14.7.7, MacBook Pro M2 macOS 15.6.1, running with Eclipse Temurin 21.0.8.

      A DESCRIPTION OF THE PROBLEM :
      If a JFrame is set to fill a HiDPI screen (such as a 4k display, or a Retina MacBook’s internal screen) (either by OS-specific means such as Rectangle, or by setting its size to Toolkit.getScreenSize()) and a button is so close to the right border of the frame that its tooltip has to be moved to the left in order to not extend beyond the display, the tooltip is rendered heavily distorted.

      REGRESSION : Last worked in version 11

      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      Use the attached code. It can be reproduced with the given font from a default macOS install, but e.g. not with Geneva.ttf.

      When the frame is showing, hover over the button in the top right corner. If you hover over the left side of the button, the tooltip is fine. If you move the pointer to the right and wait for the tooltip to reappear, at the point where the tooltip reaches the right border of the display, the tooltip gets distorted.

      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      The tooltip is showing fine, regardless of its position on the screen.
      ACTUAL -
      The tooltip is distorted, making it unreadable.

      ---------- BEGIN SOURCE ----------
      package broken.tooltips;

      import java.awt.BorderLayout;
      import java.awt.Font;
      import java.awt.FontFormatException;
      import java.awt.Toolkit;
      import java.io.File;
      import java.io.IOException;
      import javax.swing.BorderFactory;
      import javax.swing.BoxLayout;
      import javax.swing.JButton;
      import javax.swing.JFrame;
      import javax.swing.JPanel;
      import javax.swing.UIManager;
      import javax.swing.plaf.ColorUIResource;
      import javax.swing.plaf.FontUIResource;
      import javax.swing.plaf.metal.MetalLookAndFeel;
      import javax.swing.plaf.metal.MetalTheme;

      import static java.awt.BorderLayout.CENTER;
      import static java.awt.BorderLayout.EAST;

      public class BrokenTooltips {

      private static final File fontFile = new File("/System/Library/Fonts/NewYork.ttf");

      public void run() throws Exception {
      MetalLookAndFeel.setCurrentTheme(new MetalTheme() {
      @Override public String getName() { return ""; }
      @Override protected ColorUIResource getPrimary1() { return null; }
      @Override protected ColorUIResource getPrimary2() { return null; }
      @Override protected ColorUIResource getPrimary3() { return null; }
      @Override protected ColorUIResource getSecondary1() { return null; }
      @Override protected ColorUIResource getSecondary2() { return null; }
      @Override protected ColorUIResource getSecondary3() { return null; }
      @Override public FontUIResource getControlTextFont() { return null; }

      @Override
      public FontUIResource getSystemTextFont() {
      try {
      return new FontUIResource(FontUIResource.createFont(Font.TRUETYPE_FONT, fontFile).deriveFont(12f));
      } catch (FontFormatException | IOException e) {
      throw new RuntimeException(e);
      }
      }

      @Override public FontUIResource getUserTextFont() { return null; }
      @Override public FontUIResource getMenuTextFont() { return null; }
      @Override public FontUIResource getWindowTitleFont() { return null; }
      @Override public FontUIResource getSubTextFont() { return null; }
      });
      UIManager.setLookAndFeel(new MetalLookAndFeel());
      var frame = new JFrame("Broken Tooltips");
      frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
      var mainPanel = new JPanel(new BorderLayout());
      mainPanel.setBorder(BorderFactory.createEmptyBorder(15, 15, 15, 15));
      var buttonPanel = new JPanel();
      buttonPanel.setLayout(new BoxLayout(buttonPanel, BoxLayout.Y_AXIS));
      var shortButton = new JButton("Hover here");
      shortButton.setToolTipText("Button");
      buttonPanel.add(shortButton);
      mainPanel.add(buttonPanel, EAST);
      frame.getContentPane().add(mainPanel, CENTER);
      frame.setSize(Toolkit.getDefaultToolkit().getScreenSize());
      frame.setVisible(true);
      }

      public static void main(String[] args) throws Exception {
      new BrokenTooltips().run();
      }

      }

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

        1. BrokenTooltips.java
          3 kB
          Praveen Narayanaswamy
        2. Fail_Screenshot.png
          210 kB
          Praveen Narayanaswamy
        3. macOS_15.6.1 _x64.png
          42 kB
          Harshitha Onkar
        4. Pass_Screenshot.png
          214 kB
          Praveen Narayanaswamy

            jdv Jayathirth D V
            webbuggrp Webbug Group
            Votes:
            0 Vote for this issue
            Watchers:
            5 Start watching this issue

              Created:
              Updated: