I have some problem with the cursor when using JOprionPane. I set a cursor to the pharent frame, then show a dialog using this:
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");
It show the dialog, but change the cursor to the default system cursor until I close the dialog. is there any way to fix this?
How about an SSCCE? Yes it's possible, you have to "unbundle" the JOptionPane from the static method helper as you wish to do something special with it. This unfortunately means you have a little more work to do, but nothing too scary.
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);
}