문제

I have a Java Swing 응용 프로그램 개발,Mac OS X10.5 를 사용하여 Java1.5.

내가 만들려고 노력하는 사용자 지정 커서가 나타날 때 사용자의 움직임을 통해 마우스 텍스트에서는 대화입니다.커서 변경되지 않는,하지만.

때 나는 사용하지 않 JFrame 대신 JDialog,커서가 변경됩니다.그러나 나는 모든 대화 코드는 자신입니다.

를 얻을 수 있는 방법은 커서가 나타납니까?

여기에 간단한 코드를 만들 수 있습을 보여 문제점:

import javax.swing.*;
import java.awt.*;

public class CursorTest {

    public static void main(String[] args) {
        JLabel label = new JLabel("Move mouse here for hand cursor");
        label.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
        JOptionPane pane = new JOptionPane(label);
        pane.setOptions(new Object[]{"OK"});

        JDialog dialog = pane.createDialog(null, "Test Dialog");
        dialog.setVisible(true);
    }
}
도움이 되었습니까?

해결책

Java 1.5의 버그 인 것 같습니다. 처음 Java 1.6.0_07로 시도했는데 Windows XP에서 예상대로 작동했습니다. 그런 다음 Java 1.5.0_06으로 다시 고합했고 실제로 커서는 기본 상태로 유지됩니다.

MacOS에서 Java 1.6의 어려움을 알고, 나는 그것을 고치기가 어려울 것입니다 ...

버그 ID : 5079694 JDialog는 SetCursor를 존중하지 않습니다
그들은 해결 방법을 제공합니다 ...

편집] 테스트 된 해결 방법 :

public class CursorTest extends JFrame
{
  private CursorTest()
  {
  }

  private void ShowDialog()
  {
        JLabel label = new JLabel("Move mouse here for hand cursor");
        label.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
        JOptionPane pane = new JOptionPane(label);
        pane.setOptions(new Object[] { "OK" } );

        JDialog dialog = pane.createDialog(this, "Test Dialog");
        dialog.setVisible(true);
  }

  public static void main(String[] args)
  {
    SwingUtilities.invokeLater(new Runnable()
    {
      public void run()
      {
        CursorTest testFrame = new CursorTest();
        testFrame.setTitle("Test GUI");
        testFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        testFrame.setSize(500, 300);
        testFrame.setVisible(true);
        testFrame.ShowDialog();
      }
    });
  }
}

JDK & 시스템에서 잘 작동합니다.

다른 팁

감사 PhiLho,는 태양 버그 보고서 준 솔루션입니다.소유자(부모 프레임)null 이 아니어야 함을 보여주는.에 대한 기록,여기에의 수정된 버전의 예제 코드는 쇼 손으로 커서입니다.

import javax.swing.*;
import java.awt.*;

public class CursorTest {

    public static void main(String[] args) {
        JLabel label = new JLabel("Move mouse here for hand cursor");
        label.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
        JOptionPane pane = new JOptionPane(label);
        pane.setOptions(new Object[]{"OK"});

        JFrame parent = new JFrame();
        parent.setVisible(true);
        JDialog dialog = pane.createDialog(parent, "Test Dialog");
        dialog.setModal(false);
        dialog.setVisible(true);
    }
}
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top