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

[macosx] Disabled panel takes mouse input in JLayeredPane

    XMLWordPrintable

    Details

    • Type: Bug
    • Status: Closed
    • Priority: P3
    • Resolution: Duplicate
    • Affects Version/s: 8
    • Fix Version/s: None
    • Component/s: client-libs
    • Labels:

      Description

      FULL PRODUCT VERSION :
      Java(TM) SE Runtime Environment (build 1.7.0_09-b05)

      ADDITIONAL OS VERSION INFORMATION :
      Mac OS X Lion (10.7.4)

      A DESCRIPTION OF THE PROBLEM :
      In Java 1.7 a JLayeredPane with a disabled panel no longer passes the mouse event to the panel below.


      REGRESSION. Last worked in version 6u31

      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      Please try and run the LayeredPaneDemo snippet below. The mouse cursor for the " Default panel " is the crosshair cursor and the mouse cursor for the the " Palette Panel " is the default cursor. The " Palette panel " is disabled. Move the mouse cursor of the intersection of the two panels.

       

      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      The mouse cursor should be the crosshair cursor in the intersection.
      If you try and run the same example in Java 1.6 the mouse cursor in the intersection is the crosshair cursor.
      ACTUAL -
      The mouse cursor is the default cursor in the intersection, i.e. the disabled " Default panel " get the mouse events.

      REPRODUCIBILITY :
      This bug can be reproduced always.

      ---------- BEGIN SOURCE ----------
      import java.awt.Color;
      import java.awt.Cursor;
      import java.awt.Dimension;
      import java.awt.Graphics;
      import java.awt.Point;
      import java.awt.event.MouseAdapter;
      import java.awt.event.MouseEvent;

      import javax.swing.BorderFactory;
      import javax.swing.JFrame;
      import javax.swing.JLayeredPane;
      import javax.swing.JPanel;

      public class LayeredPaneDemo extends JLayeredPane {
        private static final int JLP_WIDTH = 400;
        private static final int JLP_HEIGHT = 400;
        private static final Dimension PANEL_SIZE = new Dimension(200, 200);

        public LayeredPaneDemo() {
          final JPanel defaultPanel = createPanel( " Default Panel " , new Point(10, 10), Color.cyan, true);
          defaultPanel.addMouseListener(new MouseAdapter() {
            @Override
            public void mouseClicked(final MouseEvent e) {
              System.out.println( " Mouse clicked in default panel... " );
            }
          });
          defaultPanel.setCursor(Cursor.getPredefinedCursor(Cursor.CROSSHAIR_CURSOR));
          final JPanel palettePanel = createPanel( " Palette Panel " , new Point(100, 100), Color.pink, false);
          add(palettePanel, JLayeredPane.PALETTE_LAYER);
          add(defaultPanel, JLayeredPane.DEFAULT_LAYER);
        }

        private JPanel createPanel(final String name, final Point location, final Color color, final boolean enabled) {
          final JPanel defaultPanel = new JPanel() {
            {
              setOpaque(false);
              setBorder(null);
              setEnabled(enabled);
              setFocusable(false);
              setFocusCycleRoot(false);
              setRequestFocusEnabled(false);
              setFocusTraversalPolicyProvider(false);
              setVerifyInputWhenFocusTarget(false);
            }

            @Override
            protected void paintComponent(final Graphics g) {
              g.setColor(color);
              g.fillRect(0, 0, getWidth(), getHeight());
            }
          };

          defaultPanel.setSize(PANEL_SIZE);
          defaultPanel.setLocation(location);
          defaultPanel.setBackground(color);
          defaultPanel.setBorder(BorderFactory.createTitledBorder(name));
          return defaultPanel;
        }

        @Override
        public Dimension getPreferredSize() {
          return new Dimension(JLP_WIDTH, JLP_HEIGHT);
        }

        private static void createAndShowUI() {
          final JFrame frame = new JFrame( " LayeredFun " );
          frame.getContentPane().add(new LayeredPaneDemo());
          frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
          frame.pack();
          frame.setLocationRelativeTo(null);
          frame.setVisible(true);
        }

        public static void main(final String[] args) {
          java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
              createAndShowUI();
            }
          });
        }
      }
      ---------- END SOURCE ----------

        Attachments

          Issue Links

            Activity

              People

              Assignee:
              vkarnauk Vladislav Karnaukhov
              Reporter:
              webbuggrp Webbug Group
              Votes:
              0 Vote for this issue
              Watchers:
              3 Start watching this issue

                Dates

                Created:
                Updated:
                Resolved: