import javax.swing.*;Output:
导入 java.awt.*;
public class LookAndFeelTest extends JFrame{
public LookAndFeelTest(){
//初始化 lookandfeel
initLookAndFeel();
//确保学习已应用
JFrame.setDefaultLookAndFeelDecorated(true);
//创建并配置window
JFrame frame = new JFrame(SwingApp”);
组件内容 = createComponents();
frame.getContentPane().add(contents, BorderLayout.CENTER);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
SwingUtilities.updateComponentTreeUI(框架);
//显示窗口
frame.pack();
frame.setVisible(true);
}
/*
* 通过设置
指定要使用的 lookandfeel 外观 * LOOKANDFEEL 常量
*/
final static String LOOKANDFEEL = Metal”;
public Component createComponents() {
JButton button = new JButton(Button”);
JLabel 标签 = new JLabel(LOOKANDFEEL);
JPanel 面板 = new JPanel(new GridLayout(0, 1));
panel.add(按钮);
panel.add(label);
panel.setBorder(BorderFactory.createEmptyBorder(30,30,10,30));
返回面板;
}
私有静态 void initLookAndFeel() {
String lookAndFeel = null;
if(LOOKANDFEEL != null) {
switch(LOOKANDFEEL){
Metal” box:lookAndFeel = UIManager.getCrossPlatformLookAndFeelClassName();
遗产;
系统”:lookAndFeel = UIManager.getSystemLookAndFeelClassName();
遗产;
模式”:lookAndFeel = com.sun.java.swing.plaf.pattern.PatternLookAndFeel”;
遗产;
框 GTK”:lookAndFeel = com.sun.java.swing.plaf.gtk.GTKLookAndFeel”;
遗产;
}
try {
UIManager.setLookAndFeel(lookAndFeel);
}
catch (异常 e) {
e.printStackTrace();
}
}
}
public static void main(String[] args) {
new LookAndFeelTest();
}
}
lookAndFeel = UIManager.getSystemLookAndFeelClassName();out:
lookAndFeel=com.sun.java.swing.plaf.motif.MotifLookAndFeel”;out:
Please disable your ad blocker and refresh the window to use this website.