2012-06-19 3 views
2

У меня есть проблема с курсором при использовании JOprionPane. Я поставил курсор на pharent кадра, а затем показать диалоговое окно с помощью этого:JOptionPane cursor

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

Это покажет диалог, но изменить курсор системы по умолчанию курсор на, пока не будет закрыто диалоговое окно. есть ли способ исправить это?

ответ

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

Большое спасибо! Отлично работает. –