嗨,我已经创建了示例程序,它将提供相同的外观和确认对话框的感觉,并将背景颜色设置为红色。但是我不知道我的选项的背景颜色显示为默认颜色而不是红色的问题是什么。此外,我需要在所有平台上的确认对话框相同的外观和感觉。
这是我写的代码。请帮我解决这个问题
公共类JOptionPaneBackground {
public static void main(String[] args) throws Exception {
// UIManager.setLookAndFeel(UIManager.getCrossPlatformLookAndFeelClassName());
UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
UIDefaults uiDefaults = UIManager.getLookAndFeelDefaults();
List<Object> keys = new ArrayList<Object>(uiDefaults.keySet());
Collections.sort(keys, new Comparator<Object>() {
public int compare(Object o1, Object o2) {
return (o1.toString()).compareTo(o2.toString());
}
});
for (Object key : keys) {
System.out.println(String.format("%-40s = %s", key, uiDefaults.get(key)));
}
UIManager.put("OptionPane.background", Color.red);
UIManager.put("Panel.background", Color.red);
JOptionPane.showConfirmDialog(null, "Hello World!");
}}
发布于 2010-04-12 12:58:09
我认为您需要获取一个新的UIManager实例,并在该实例上设置窗格的颜色属性。
在here上查找代码片段
这段代码在windows机器上运行得很好:
public class JOptionPaneBackground {
public static void main(String[] args) throws Exception {
UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
UIManager.put("OptionPane.background", Color.RED);
UIManager.put("Panel.background", Color.RED);
JOptionPane.showConfirmDialog(null, "Hello World!");
}}
https://stackoverflow.com/questions/2619901
复制相似问题