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

JDialog doesn't respect setCursor

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Fixed
    • Icon: P3 P3
    • 6
    • 5.0, 5.0u17-crev, 6
    • client-libs
    • b47
    • x86, sparc, itanium
    • linux, solaris_1, windows_2000, windows_xp, windows_vista

      Name: rmT116609 Date: 07/28/2004


      FULL PRODUCT VERSION :
      java version "1.5.0-beta"
      Java(TM) 2 Runtime Environment, Standard Edition (build 1.5.0-beta-b32c)
      Java HotSpot(TM) Client VM (build 1.5.0-beta-b32c, mixed mode)

      java version "1.5.0-beta2"
      Java(TM) 2 Runtime Environment, Standard Edition (build 1.5.0-beta2-b51)
      Java HotSpot(TM) Client VM (build 1.5.0-beta2-b51, mixed mode, sharing)

      ADDITIONAL OS VERSION INFORMATION :
      Microsoft Windows XP [Version 5.1.2600]

      A DESCRIPTION OF THE PROBLEM :
      When using a JDialog, setting a cusor on one if its child components (say a label added to it) - the cursor is ignored. This works fine with JFrame however.


      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      When hovering the mouse over a central component (a JLabel in the BorderLayout.CENTER position), the mouse cursor should change from the pointer to a hand.
      ACTUAL -
      The cursor stay the same (e.g. a pointer) when the JDialog is used, but it works fine when a JFrame is used.

      REPRODUCIBILITY :
      This bug can be reproduced always.

      ---------- BEGIN SOURCE ----------
      import java.awt.BorderLayout;
      import java.awt.Color;
      import java.awt.Cursor;

      import javax.swing.JDialog;
      import javax.swing.JFrame;
      import javax.swing.JLabel;
      import javax.swing.border.LineBorder;

      import junit.framework.TestCase;

      /**
       * Test case to demonstrate problem/difference between JDialog and JFrame
       * cursor.
       */
      public class JDialogCursor_TestCase extends TestCase
      {
        public void testJDialogCursor()
         throws Exception
        {
          JDialog dialog = new JDialog();
          dialog.setTitle("JDialog cursor test (fails)");
          dialog.setLayout(new BorderLayout());
          dialog.add(new JLabel("Close this dialog when ready to continue"), BorderLayout.NORTH);
          JLabel centerLabel = new JLabel("Cursor should be a hand in this label area");
          centerLabel.setBorder(new LineBorder(Color.BLACK));
          centerLabel.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
          dialog.add(centerLabel, BorderLayout.CENTER);
          dialog.setSize(400, 200);
          dialog.setVisible(true);
          while (dialog.isVisible())
          {
            Thread.sleep(1000);
          }
          dialog.dispose();
        }
        
        public void testJFrameCursor()
         throws Exception
        {
          JFrame frame = new JFrame();
          frame.setTitle("JFrame cursor test (works)");
          frame.setLayout(new BorderLayout());
          frame.add(new JLabel("Close this frame when ready to continue"), BorderLayout.NORTH);
          JLabel centerLabel = new JLabel("Cursor should be a hand in this label area");
          centerLabel.setBorder(new LineBorder(Color.BLACK));
          centerLabel.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
          frame.add(centerLabel, BorderLayout.CENTER);
          frame.setSize(400, 200);
          frame.setVisible(true);
          while (frame.isVisible())
          {
            Thread.sleep(1000);
          }
          frame.dispose();
        }
      }

      ---------- END SOURCE ----------

      CUSTOMER SUBMITTED WORKAROUND :
      Use JFrame instead of JDialog. However, JFrame does not have the modality control like a JDialog does.
      (Incident Review ID: 277202)
      ======================================================================

            osemenovsunw Oleg Semenov (Inactive)
            rmandalasunw Ranjith Mandala (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: