Reputation: 5373
In many native OS X applications, there are dialog boxes that have a default option (in blue) and a different option (in outlined blue) that are initially set. This allows a user to use enter and space, respectively, to choose between two different common options.
I want to be able to replicate this in a java application. Using JOptionPane in the following way produces something close, but the default option (supplied as the initialValue
parameter) is both focused and the default; The blue outline (and the button activated via the spacebar) should be on the left-most button, but it isn't.
int showOptionPane(JFrame parent, String file) {
String[] selections = {"Save", "Cancel", "Don't Save"};
return JOptionPane.showOptionDialog(parent,
"Do you want to save changes to: " + file + "?",
"Save Work?",
JOptionPane.YES_NO_CANCEL_OPTION,
JOptionPane.PLAIN_MESSAGE,
null, selections, selections[0]);
}
I have tried pulling out the source for JOptionPane.showOptionDialog
in an attempt to tweak which button got its focus when displayed to the user, but I was having trouble getting at the buttons themselves (since I think those are specified at the pluggable-look-and-feel). How do I get a button focused that is distinct from the default button?
Upvotes: 1
Views: 981