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

setCursor does not work for lightweight component

XMLWordPrintable

    • b01
    • sparc
    • solaris_2.5.1
    • Not verified

      setCursor called by a lightweight component does not have any effect. In the following example, the mouseEntered() method calls the setCursor() to change the cursor to "HAND_CURSOR", but it doesn't work.


      /*
       * %W% %G% SMI
       * Copyright (c) 1997 Sun Microsystems, Inc. All Rights Reserved.
       *
       */

      import java.awt.Component;
      import java.awt.Cursor;
      import java.awt.Dimension;
      import java.awt.Font;
      import java.awt.FontMetrics;
      import java.awt.Frame;
      import java.awt.FlowLayout;
      import java.awt.Graphics;
      import java.awt.Point;
      import java.awt.event.MouseListener;
      import java.awt.event.MouseEvent;

      public class LWRect extends Component implements MouseListener {


      public LWRect() {
      addMouseListener(this);
      }

      public void paint(Graphics g) {
      Dimension dim = getSize();
      g.setColor(getForeground());
      g.fillRect(0, 0, dim.width, dim.height);
      }

      public Dimension getPreferredSize() {
      return new Dimension(48, 48);
      }

      public Dimension preferredSize() {
      return getPreferredSize();
      }

      public void mouseClicked(MouseEvent e) {
      System.out.println("Mouse Clicked...");
      }

      public void mousePressed(MouseEvent e) {
      System.out.println("Mouse Pressed...");
      }

      public void mouseReleased(MouseEvent e) {
      System.out.println("Mouse Released...");
      }

      public void mouseExited(MouseEvent e) {
      System.out.println("Mouse Exited...");
      setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR));
      }

      public void mouseEntered(MouseEvent e) {
      System.out.println("Mouse Entered...");
      setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
      }

      public static void main(String argv[]) {
      Frame app = new Frame();
      app.setLayout(new FlowLayout());
      LWRect rect = new LWRect();
      app.add(rect);

      app.pack();
      app.show();
      }
      }

      sofyan.nugroho@Eng 1997-04-28

      -------------------------------------------------------------------

      I hit this too. The thing that took me a little by surprise was
      that I was catching mouse events in my lightweight container, but I
      was doing a setCursor on my parent container which was a normal
      panel, and it still wasn't taking effect! I guess that fits with
      the evaluation...

      Note that I'm still seeing this in the current JDK1.1-AWT workspace.

      KGH 5/5/97


            tprinzing Tim Prinzing
            duke J. Duke
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: