2012-06-19 4 views
2

JOprionPane을 사용할 때 커서에 문제가 있습니다.JOptionPane 커서

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

그것은 대화 상자를 보여 주지만, 내가 대화 상자를 닫을 때까지 기본 시스템 커서 커서를 변경 :이를 사용하여 대화 상자를 보여 다음의 pharent 프레임에 커서를 설정합니다. 이 문제를 해결할 방법이 있습니까?

답변

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); 
} 
+0

감사합니다. 그것은 매력처럼 작동합니다. –