在使用JOprionPane时,我遇到了一些光标问题。我将光标设置为pharent框架,然后使用以下命令显示一个对话框:
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");它会显示对话框,但会将光标更改为默认系统光标,直到我关闭该对话框。有没有办法解决这个问题?
发布于 2012-06-20 07:36:55
那SSCCE呢?是的,这是可能的,你必须从静态方法帮助器中“解绑”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);
}https://stackoverflow.com/questions/11110734
复制相似问题