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

Swing heavyweight popup is displayed incorrectly with the dual monitor setup

    Details

    • Subcomponent:
    • Introduced In Version:
      9
    • CPU:
      x86_64
    • OS:
      windows_10

      Description

      ADDITIONAL SYSTEM INFORMATION :
      OS: Windows 10 x64.
      Java version: JDK 10.0.2, also reproducible with 11.0.3, 12.0.1.

      A DESCRIPTION OF THE PROBLEM :
      With the dual monitor setup, when the heavyweight popup window is requested to show on a non-primary display, it is showed on a primary display instead, at seemingly random location.

      This behavior is only reproducible with JDK 10 and higher.

      REGRESSION : Last worked in version 8u212

      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      1. Run the attached example
      2. Drag the main frame from the primary display to a non-primary one.
      3. Click "Create Popup" button.

      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      The popup appears at the correct location right under the main frame.
      ACTUAL -
      The popup is showed on the other (primary) display.

      ---------- BEGIN SOURCE ----------
      import javax.swing.*;
      import java.awt.*;
      import java.awt.event.ActionEvent;
      import java.awt.event.ActionListener;

      public class HeavyWeightPopupSample {

          static class ShowPopupActionListener implements ActionListener {

              private final Component component;

              ShowPopupActionListener(Component component) {
                  this.component = component;
              }

              @Override
              public void actionPerformed(ActionEvent actionEvent) {
                  JButton button = new JButton("Hello world");
                  PopupFactory factory = PopupFactory.getSharedInstance();

                  // Set the popup coordinates such that the popup window is not "parented" by the
                  // component and becomes a heavyweight window.
                  final int popupX = component.getX() + 351;
                  final int popupY = component.getY() + 251;
                  Popup popup = factory.getPopup(component, button, popupX, popupY);
                  popup.show();
              }
          }

          public static void main(final String[] args) {
              JFrame frame = new JFrame("HeavyWeightPopup Sample");
              ActionListener actionListener = new ShowPopupActionListener(frame);
              JButton start = new JButton("Create Popup");
              start.addActionListener(actionListener);
              frame.add(start);
              frame.setSize(350, 250);
              frame.setVisible(true);
          }
      }
      ---------- END SOURCE ----------

      FREQUENCY : always


        Attachments

          Issue Links

            Activity

              People

              • Assignee:
                psadhukhan Prasanta Sadhukhan
                Reporter:
                webbuggrp Webbug Group
              • Votes:
                0 Vote for this issue
                Watchers:
                4 Start watching this issue

                Dates

                • Created:
                  Updated: