javax.swing.UIManager类和LookAndFeel类
javax.swing.UIManager类
javax.swing.UIManager类是Swing界面管理核心,管理Swing应用程序样式。
LookAndFeel类
与javax.swing.UIManager类密切相关的就是LookAndFeel抽象类。它除了提供static方法,还定义抽象的个性化设置方法由子类实现。
Sun提供了三个LookAndFeel子类:
javax.swing.plaf.metal.MetalLookAndFeel(Metal样式)
com.sun.java.swing.plaf.motif.MotifLookAndFeel(Motif样式)
com.sun.java.swing.plaf.windows.WindowsLookAndFeel(Windows样式)。
Java中的几种LookandFeel(此部分代码在main方法打开GUI界面之前实现)
1、Metal风格(默认)
String lookAndFeel =“javax.swing.plaf.metal.MetalLookAndFeel”;
UIManager.setLookAndFeel(lookAndFeel);
2、Windows风格
String lookAndFeel =“com.sun.java.swing.plaf.windows.WindowsLookAndFeel”;
UIManager.setLookAndFeel(lookAndFeel);
3、Windows Classic风格
String lookAndFeel =“com.sun.java.swing.plaf.windows.WindowsClassicLookAndFeel”;
UIManager.setLookAndFeel(lookAndFeel);
4、Motif风格
String lookAndFeel =“com.sun.java.swing.plaf.motif.MotifLookAndFeel”;
UIManager.setLookAndFeel(lookAndFeel);
5、Mac风格 (需要在相关的操作系统上方可实现)
String lookAndFeel =“com.sun.java.swing.plaf.mac.MacLookAndFeel”;
UIManager.setLookAndFeel(lookAndFeel);
6、GTK风格 (需要在相关的操作系统上方可实现)
String lookAndFeel =“com.sun.java.swing.plaf.gtk.GTKLookAndFeel”;
UIManager.setLookAndFeel(lookAndFeel);
7、可跨平台的默认风格
String lookAndFeel =UIManager.getCrossPlatformLookAndFeelClassName();
UIManager.setLookAndFeel(lookAndFeel);
8、当前系统的风格
String lookAndFeel =UIManager.getSystemLookAndFeelClassName();
UIManager.setLookAndFeel(lookAndFeel);
————————————————
原文链接
本文详细介绍了Java Swing中UIManager类和LookAndFeel类的作用,列举了多种预设的界面风格,如Metal、Windows、Motif等,并提供了代码示例,展示了如何在Swing应用中切换不同的界面风格。
6127

被折叠的 条评论
为什么被折叠?



