如何设置Java桌面程序界面外观
(How to Set the Look and Feel)
1.使用UIManager.setLookAndFeel通过编程来指定界面外观.
示例代码如下:
import javax.swing.*;
import java.awt.*;
public class Hello extends JFrame {
public Hello() {
setPreferredSize(new Dimension(600, 400));
pack();
setDefaultCloseOperation(EXIT_ON_CLOSE);
setVisible(true);
}
public static void main(String[] args) {
try {
String lookAndFeel =
UIManager.getCrossPlatformLookAndFeelClassName();
UIManager.setLookAndFeel(lookAndFeel);
} catch (Exception e) {}
new Hello();
}
}
方法setLookAndFeel中的参数是类LookAndFeel的子类的全称(fully qualified name). 要设置Java界面外观(Java Look and Feel), 我们使用getCrossPlatformLookAndFeelClassName方法. 如果你想设置为程序所运行的平台的界面外观, 可以使用getSystemLookAndFeelClassName方法. 要设置特殊的UI, 你可以使用具体的类名. 例如你想设置Wi