首页javabasicJava Swing - 如何在Swing JDialog中使用自定义光标

Java Swing - 如何在Swing JDialog中使用自定义光标

我们想知道如何在Swing JDialog中使用自定义光标。
import java.awt.Cursor;

import javax.swing.JDialog;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JOptionPane;

public class Main extends JFrame {
  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) {
    Main testFrame = new Main();
    testFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    testFrame.setSize(500, 300);
    testFrame.setVisible(true);
    testFrame.ShowDialog();
  }
}