我正在开发和运行我的Java应用程序,它在OS X Mountain Lion上运行。我添加了一个自定义对话框的"Yes"和"No"选项。然而,当我在Windows 7上运行我的应用程序时,我注意到"Yes"和"No"选项被颠倒了。为了解决这个UI故障,我添加了以下代码:
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;
}
有人能告诉我为什么我会遇到我在第一次描述中提到的问题吗?我有一种感觉,这与应用程序的 L&F 有关。谢谢!
JOptionPane
时才会出现。这是我第一次在不同平台上测试我的应用程序,所以看到这种行为发生我感到很惊讶。 - BJ Dela Cruz