I am developing and running my Java application on OS X Mountain Lion, and I added "Yes" and "No" options to a custom dialog box. However, when I ran my application on Windows 7, I noticed that the "Yes" and "No" options were reversed. To fix this UI glitch, I added this code:
String msg = "Are you sure you want to cancel the selected bookings?";
String[] options = new String[] { "Yes", "No" };
int noOption = 1;
String os = System.getProperty("os.name").toLowerCase();
if ("mac os x".equals(os)) {
options = new String[] { "No", "Yes" };
noOption = 0;
}
int option =
JOptionPane.showOptionDialog(null, msg, "Confirm Unbooking",
JOptionPane.OK_CANCEL_OPTION, JOptionPane.INFORMATION_MESSAGE, null, options,
options[noOption]);
if (option == noOption) {
return;
}
Can someone tell me why I experienced the issue that I described in the first place? I have a feeling that it has to do with the L&F of the application. Thanks!
It is indeed a L&F feature that performs this (this is not a UI glitch). I would recommend not to change that for a better user-experience. Users expect application to be consistent on a platform. Windows & Linux are used to have buttons displayed from left to right, while MacOS are used to have buttons displayed from right to left.
See here two samples:
Windows:
MacOS:
See how on MacOS, the most important button is displayed on the far right, while it is the opposite on Windows.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With