我在项目中使用Nimbus外观。然而,尽管每个GUI都有Nimbus的外观和感觉,但JFrame总是有JComponent的外观和感觉。
JFrame怎么会有Nimbus的外观和感觉呢?
编辑:操作系统: Windows XP
发布于 2011-09-30 23:24:24
尝试使用以下命令:
JFrame.setDefaultLookAndFeelDecorated(true); //before creating JFrames有关更多信息,请参阅教程中的How to Set the Look and Feel。
import javax.swing.*;
class FrameLook {
public static void showFrame(String plaf) {
try {
UIManager.setLookAndFeel(plaf);
} catch(Exception e) {
e.printStackTrace();
}
JFrame f = new JFrame(plaf);
f.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
f.setSize(400,100);
f.setLocationByPlatform(true);
f.setDefaultLookAndFeelDecorated(true);
f.setVisible(true);
}
public static void main(String[] args) {
showFrame(UIManager.getSystemLookAndFeelClassName());
showFrame(UIManager.getCrossPlatformLookAndFeelClassName());
showFrame("com.sun.java.swing.plaf.nimbus.NimbusLookAndFeel");
}
}

发布于 2011-10-01 06:28:25
证实了@Andrew的怀疑,setDefaultLookAndFeelDecorated()说,当支持时,“新创建的JFrames将由当前的LookAndFeel提供它们的Window装饰。”我更改了大小以查看整个标题。

import javax.swing.*;
class FrameLook {
public static void showFrame(String plaf) {
try {
UIManager.setLookAndFeel(plaf);
} catch (Exception e) {
e.printStackTrace(System.out);
}
JFrame f = new JFrame(plaf);
f.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
f.setSize(500, 100);
f.setLocationByPlatform(true);
JFrame.setDefaultLookAndFeelDecorated(true);
f.setVisible(true);
}
public static void main(String[] args) {
showFrame(UIManager.getSystemLookAndFeelClassName());
showFrame(UIManager.getCrossPlatformLookAndFeelClassName());
showFrame("com.sun.java.swing.plaf.nimbus.NimbusLookAndFeel");
}
}发布于 2012-02-03 05:15:51
以及基于Windows Classic UI for XP进行确认。

https://stackoverflow.com/questions/7612592
复制相似问题