2

JOprionPaneを使用しているときにカーソルに問題があります。カーソルをファレントフレームに設定し、次のコマンドを使用してダイアログを表示します。

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で特別なことをしたい場合は、静的メソッドヘルパーから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 に答える