使用Swing开发用户界面时,你是否为Swing默认界面不够漂亮而烦恼呢,以前的办法是使用大量的图片来构建用户界面,这种方法虽然可以实现漂亮的效果,但是实现成本太高,不够实用。
自从Swing支持不同显示风格以后,我们也可以使用Swing快速地开发出漂亮的用户界面了,而且使用这种机制支持用户动态切换显示风格。Swing实现显示风格切换主要是通过javax.swing.UIManager类的静态成员方法setLookAndFeel实现的,该方法的原型如下:
public static void setLookAndFeel(String className)
throws ClassNotFoundException,
InstantiationException,
IllegalAccessException,
UnsupportedLookAndFeelException
Loads the LookAndFeel specified by the given class name, using the current thread's context class loader, and passes it to setLookAndFeel(LookAndFeel).
该方法接受一个字符串类型的className作为显示风格标识的输入参数。
为了使用方便,我们依然将这个独立功能封装在一个函数中,下面给出该函数的实现代码:
/**
* 设置显示风格
* @param strStyle
*/
public static void setUIStyle(String strStyle,Component target){
try {