Java JOptionPane光标
使用JOprionPane时,光标出现了一些问题。我将光标设置到pharent框架,然后使用以下命令显示对话框:Java JOptionPane光标,java,swing,cursor,joptionpane,Java,Swing,Cursor,Joptionpane,使用JOprionPane时,光标出现了一些问题。我将光标设置到pharent框架,然后使用以下命令显示对话框: Object[] possibilities = {"ham", "spam", "yam"}; String s = (String) JOptionPane.showInputDialog(MagicCollectorClient.getMainFrame(),"Complete the sentence:\n\"Green eggs and...\"",
Object[] possibilities = {"ham", "spam", "yam"};
String s = (String) JOptionPane.showInputDialog(MagicCollectorClient.getMainFrame(),"Complete the sentence:\n\"Green eggs and...\"",
"Customized Dialog",JOptionPane.PLAIN_MESSAGE,null,possibilities,"ham");
它显示对话框,但将光标更改为默认系统光标,直到关闭对话框。有什么办法可以解决这个问题吗?用一台电脑怎么样?是的,这是可能的,您必须将JOptionPane从静态方法助手中“解除绑定”,因为您希望对它做一些特殊的处理。不幸的是,这意味着你还有一点工作要做,但没有什么太可怕的
public static void main(String[] args) {
JFrame parent = new JFrame();
parent.setSize(400, 400);
parent.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
parent.setVisible(true);
Object[] possibilities = { "ham", "spam", "yam" };
// raw pane
JOptionPane optionPane = new JOptionPane(
"Complete the sentence:\n\"Green eggs and...\"",
JOptionPane.PLAIN_MESSAGE, JOptionPane.DEFAULT_OPTION, null,
possibilities, possibilities[0]);
// create a dialog for it with the title
JDialog dialog = optionPane.createDialog("Customized Dialog");
// special code - in this case make the cursors match
dialog.setCursor(parent.getCursor());
// show it
dialog.setVisible(true);
// blocking call, gets the selection
String s = (String) optionPane.getValue();
System.out.println("Selected " + s);
}