src/share/classes/sun/swing/JLightweightFrame.java

Print this page

        

@@ -31,12 +31,13 @@
 import java.awt.Container;
 import java.awt.Dimension;
 import java.awt.EventQueue;
 import java.awt.Graphics;
 import java.awt.Graphics2D;
+import java.awt.MouseInfo;
+import java.awt.Point;
 import java.awt.Rectangle;
-import java.awt.event.ComponentListener;
 import java.awt.event.ContainerEvent;
 import java.awt.event.ContainerListener;
 import java.awt.image.BufferedImage;
 import java.awt.image.DataBufferInt;
 import java.beans.PropertyChangeEvent;

@@ -46,10 +47,11 @@
 import javax.swing.JLayeredPane;
 import javax.swing.JPanel;
 import javax.swing.JRootPane;
 import javax.swing.LayoutFocusTraversalPolicy;
 import javax.swing.RootPaneContainer;
+import javax.swing.SwingUtilities;
 
 import sun.awt.LightweightFrame;
 import sun.security.action.GetPropertyAction;
 
 /**

@@ -86,10 +88,19 @@
     private boolean copyBufferEnabled;
     private int[] copyBuffer;
 
     private PropertyChangeListener layoutSizeListener;
 
+    static {
+        SwingAccessor.setJLightweightFrameAccessor(new SwingAccessor.JLightweightFrameAccessor() {
+            @Override
+            public void updateCursor(JLightweightFrame frame) {
+                frame.updateClientCursor();
+            }
+        });
+    }
+
     /**
      * Constructs a new, initially invisible {@code JLightweightFrame}
      * instance.
      */
     public JLightweightFrame() {

@@ -356,6 +367,23 @@
 
     @Override
     public Component getGlassPane() {
         return getRootPane().getGlassPane();
     }
+
+
+    /*
+     * Notifies client toolkit that it should change a cursor.
+     *
+     * Called from the peer via SwingAccessor, because the
+     * Component.updateCursorImmediately method is final
+     * and could not be overridden.
+     */
+    private void updateClientCursor() {
+        Point p = MouseInfo.getPointerInfo().getLocation();
+        SwingUtilities.convertPointFromScreen(p, this);
+        Component target = SwingUtilities.getDeepestComponentAt(this, p.x, p.y);
+        if (target != null) {
+            content.setCursor(target.getCursor());
+        }
+    }
 }