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

JPopupMenu is not showing at the right position

XMLWordPrintable

    • 9
    • x86_64
    • windows_10

      ADDITIONAL SYSTEM INFORMATION :
      JDK 11.0.3 on a Windows 1ß 64 bit system
      Two monitors, main monitor standard, left of it same monitor but scaled by 125%


      A DESCRIPTION OF THE PROBLEM :
      The very first time a Jpopupmenu is shown on a second monitor which is scaled, the popup is shown at the wrong position.
      When I show the popup the second time it shows correct.


      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      run the program and move the window to the scaled monitor.
      Click the button and it shows a popup at the clickpoint

      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      Popup shows where i clicked
      ACTUAL -
      Popup shows on wrong location +x, -y

      ---------- BEGIN SOURCE ----------
      package com.itzmedi.viewer.viewing;

      import java.awt.FlowLayout;
      import java.awt.event.MouseEvent;
      import java.awt.event.MouseListener;

      import javax.swing.JButton;
      import javax.swing.JFrame;
      import javax.swing.JLabel;
      import javax.swing.JPopupMenu;

      public class TestGD implements MouseListener {
          private JPopupMenu popup = null;
          
          public static void main(String[] args) {
              new TestGD().go();
          }
          private void go() {
              JButton btn = new JButton("click");
              btn.addMouseListener(this);

              JFrame frame = new JFrame();
              frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
              frame.setLayout(new FlowLayout());
              frame.add(btn);
              frame.setSize(300,100);
              frame.setVisible(true);
          }
          @Override
          public void mousePressed(MouseEvent e) {
              popup = new JPopupMenu();
              popup.add(new JLabel("Lorem"));
              popup.add(new JLabel("ipsum"));
              popup.add(new JLabel("dolor"));
              popup.add(new JLabel("sit"));
              popup.show((JButton)e.getSource(), e.getPoint().x, e.getPoint().y);
          }
          @Override
          public void mouseReleased(MouseEvent e) {
              if (popup != null) {
                  popup.setVisible(false);
              }
          }
          @Override public void mouseEntered(MouseEvent e) { }
          @Override public void mouseExited(MouseEvent e) { }
          @Override public void mouseClicked(MouseEvent e) { }
      }
      ---------- 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: