Java Swing - 如何在Swing JDialog中使用自定義光標(biāo)
我們想知道如何在Swing JDialog中使用自定義光標(biāo)。
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();
}
}