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

Enabling Translucent Frame with setBackground disables HiDPI

    XMLWordPrintable

Details

    • x86
    • other

    Description

      FULL PRODUCT VERSION :
      java version "9"
      Java(TM) SE Runtime Environment (build 9+181)
      Java HotSpot(TM) 64-Bit Server VM (build 9+181, mixed mode)

      ADDITIONAL OS VERSION INFORMATION :
      Microsoft Windows [Version 10.0.15063]

      EXTRA RELEVANT SYSTEM CONFIGURATION :
      system display scaling is set to 200%

      A DESCRIPTION OF THE PROBLEM :
      When attempting to set a shaped/translucent window via Frame#setBackground, HiDPI mode becomes disabled for most/all Swing component.

      Frame#setOpacity appears to work correctly.

      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      Run example application listed below on a HiDPI display. Comment out #setBackground call to see expected scaling.

      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      Swing components are scaled according to Windows settings.
      ACTUAL -
      Swing components are not scaled.

      REPRODUCIBILITY :
      This bug can be reproduced always.

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

      public class Main {

      public static void main(String[] args) throws Exception {
          JFrame frame = new JFrame("HiDPI test");
          JPanel panel = new JPanel(new GridLayout(2, 0));
          panel.add(new JLabel("Some text"));
          panel.add(new JButton("A button"));
          frame.setContentPane(panel);

          frame.setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
          frame.setUndecorated(true);
          frame.setBackground(new Color(0, 0, 0, .5f)); // this line disabled HiDPI
          // frame.setOpacity(.5f);
          frame.pack();
          frame.setVisible(true);
      }

      }
      ---------- END SOURCE ----------

      Attachments

        Issue Links

          Activity

            People

              pbansal Pankaj Bansal (Inactive)
              webbuggrp Webbug Group
              Votes:
              0 Vote for this issue
              Watchers:
              7 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved: