Reputation: 11327
When I use default L&F the mnemonics are shown directly. When I use Windows L&F the mnemonics go visible only if I press "Alt" key. Is it possible to control this feature (turn on the behaviour of Windows L&F for default L&F)?
Here is the code to reproduce (probably works only for Windows)
import java.util.Locale;
import javax.swing.JOptionPane;
import javax.swing.UIManager;
public class OptionPaneTest {
public static void main(String[] args) throws Exception {
Locale.setDefault(Locale.ENGLISH);
JOptionPane.showConfirmDialog(null, "Test Message", "Test title", JOptionPane.YES_NO_CANCEL_OPTION);
UIManager.setLookAndFeel("com.sun.java.swing.plaf.windows.WindowsLookAndFeel"); // don't know whether it works for Mac
JOptionPane.showConfirmDialog(null, "Test Message", "Test title", JOptionPane.YES_NO_CANCEL_OPTION);
}
}
Here ist the image for default L&F (mnemonics are visible by default)
Here is the image for Win L&F (mnemonics are invisible by default)
But they go visible when I press "Alt" key
Upvotes: 3
Views: 161
Reputation: 9833
Not sure if it works on all Windows
but you could try UIManager.put("Button.showMnemonics", true);
:
import java.awt.EventQueue;
import java.util.Locale;
import javax.swing.JOptionPane;
import javax.swing.UIManager;
public class OptionPaneTest2 {
public static void main(String[] args) {
EventQueue.invokeLater(new Runnable() {
@Override public void run() {
createAndShowGUI();
}
});
}
public static void createAndShowGUI() {
try {
Locale.setDefault(Locale.ENGLISH);
JOptionPane.showConfirmDialog(
null, "Message", "title", JOptionPane.YES_NO_CANCEL_OPTION);
UIManager.setLookAndFeel("com.sun.java.swing.plaf.windows.WindowsLookAndFeel");
JOptionPane.showConfirmDialog(
null, "Message", "title", JOptionPane.YES_NO_CANCEL_OPTION);
UIManager.put("Button.showMnemonics", true);
JOptionPane.showConfirmDialog(
null, "Message", "title", JOptionPane.YES_NO_CANCEL_OPTION);
} catch (Exception e) {
e.printStackTrace();
}
}
}
Upvotes: 2