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

getLocationOnScreen() always returns (0, 0) for mouse wheel events

    Details

    • Subcomponent:
    • Resolved In Build:
      b80
    • CPU:
      generic
    • OS:
      windows

      Backports

        Description

        Run the following test on Windows and check coordinates (printed to stdout) for mouse pressed and mouse wheel events. If you see (0, 0) is always returned for event.getLocationOnScreen(), the bug is reproduced. On linux/solaris the test works correctly.

        import java.awt.*;
        import java.awt.event.*;

        import javax.swing.*;

        public class MouseWheelXY {
            public static void main(String[] args) {
        SwingUtilities.invokeLater(new Runnable() {
        @Override
        public void run() {
        new MouseWheelXY().createGUI();
        }
        });
            }
            private MouseAdapter mouseListener = new MouseAdapter() {
        @Override
        public void mousePressed(MouseEvent e) {
        printEvent(e, "Button pressed");
        }
        @Override
        public void mouseWheelMoved(MouseWheelEvent e) {
        printEvent(e, "Wheel moved");
        }
            };
            private void createGUI() {
        JFrame frame = new JFrame();
        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        JPanel labelPanel = new JPanel(new GridLayout(0, 1));
        frame.add(labelPanel);
        for (int index = 0; index < 10; index++) {
        String name = "Label " + index;
        JLabel label = new JLabel(name);
        label.setName(name);
        label.addMouseWheelListener(mouseListener);
        label.addMouseListener(mouseListener);
        labelPanel.add(label);
        }
        frame.pack();
        frame.setLocationRelativeTo(null);
        frame.setVisible(true);
            }
            private void printEvent(MouseEvent e, String message) {
        System.out.println(message);
        System.out.println("Name " + e.getComponent().getName());
        System.out.println("getPoint() " + e.getPoint());
        System.out.println("getLocationOnScreen() " + e.getLocationOnScreen());
            }
        }

          Attachments

            Issue Links

              Activity

                People

                • Assignee:
                  serb Sergey Bylokhov
                  Reporter:
                  art Artem Ananiev (Inactive)
                • Votes:
                  0 Vote for this issue
                  Watchers:
                  2 Start watching this issue

                  Dates

                  • Created:
                    Updated:
                    Resolved:
                    Imported:
                    Indexed: