JavaC002—应用程序界面外观UIManager类和LookAndFeel类


 /**
        * 设置图形界面外观
        * java的图形界面外观有3种,默认是java的金属外观,还有就是windows系统,motif系统外观.
        * 1、Metal风格 (默认) UIManager.setLookAndFeel("javax.swing.plaf.metal.MetalLookAndFeel"); 
        * 2、Windows风格 UIManager.setLookAndFeel("com.sun.java.swing.plaf.windows.WindowsLookAndFeel"); 
        * 3、Windows Classic风格 UIManager.setLookAndFeel("com.sun.java.swing.plaf.windows.WindowsClassicLookAndFeel");
        * 4、Motif风格UIManager.setLookAndFeel("com.sun.java.swing.plaf.motif.MotifLookAndFeel");
        * 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);
        * */
--------------------- 
作者:奔跑的小象 
来源:优快云 
原文:https://blog.youkuaiyun.com/u010022051/article/details/52671860?utm_source=copy 
版权声明:本文为博主原创文章,转载请附上博文链接!


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);
一个实例
1、若是改变整个应用程序的观感,则代码为:


2、若是改变某个面板的观感,则代码为:
UIManager.setLookAndFeel(观感名);
SwingUtilities.updateComponentTreeUI(面板引用);
以上代码必须能够被捕获异常,否则报错。

--------------------- 
作者:披Zhe羊皮De狼 
来源:优快云 
原文:https://blog.youkuaiyun.com/u010995220/article/details/49847307?utm_source=copy 
版权声明:本文为博主原创文章,转载请附上博文链接!


 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值