下面我定义了4种观感,是我自己机子存在的
final String METAL = "javax.swing.plaf.metal.MetalLookAndFeel";
final String CDE = "com.sun.java.swing.plaf.motif.MotifLookAndFeel";
final String WINDOWS = "com.sun.java.swing.plaf.windows.WindowsLookAndFeel";
final String WINDOWS_CLASSIC = "com.sun.java.swing.plaf.windows.WindowsClassicLookAndFeel";
1、在JFrame的构造函数中设置观感
try
{
UIManager.setLookAndFeel(WINDOWS);//在此设置要显示的观感
} catch (ClassNotFoundException e)
{
// TODO Auto-generated catch block
e.printStackTrace();
} catch (InstantiationException e)
{
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IllegalAccessException e)
{
// TODO Auto-generated catch block
e.printStackTrace();
} catch (UnsupportedLookAndFeelException e)
{
// TODO Auto-generated catch block
e.printStackTrace();
}
SwingUtilities.updateComponentTreeUI(this);//必须的,改变观感。Dialog是我自己定义的要感变观感的类
2、在main方法中设置
不需要SwingUtilities.updateComponentTreeUI(this)了,因为在初始化swing组件之前设定了观感。
try
{
//UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());//设置为本机系统默认观感
UIManager.setLookAndFeel(WINDOWS_CLASSIC);
} catch (Exception e)
{
e.printStackTrace();
}