2

使用 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");

它显示对话框,但将光标更改为默认系统光标,直到我关闭对话框。有没有什么办法解决这一问题?

4

1 回答 1

3

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);
}
于 2012-06-19T23:36:54.943 回答