一直觉得windows下的Java运行界面不是很好看,今天将其皮肤更换为了Mac OS X的苹果界面。
通过quaqua可以实现Mac界面效果,下载地址:http://www.randelshofer.ch/quaqua/download.html。
首先新建一个eclipse项目,然后将quaqua.jar导入到项目中,选择Build Path->Configure Build Path...,
在Libraries中选择Add Extrnal JARs,选择quaqua.jar。选择ok。
测试代码:
import java.awt.*;
import javax.swing.*;
import ch.randelshofer.quaqua.util.Methods;
public class TestMac extends JComponent{
private static void createShowGUI(){
JFrame frame = new JFrame("Mac");
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setSize(600,600);
frame.add(new TestMac());
frame.setVisible(true);
}
public static void main(String[] args){
System.setProperty("Quaqua.tabLayoutPolicy","wrap");
if (! System.getProperty("os.name").toLowerCase().startsWith("mac")) { //如果不是Mac os x,则更改窗体样式。
try {
Methods.invokeStatic(JFrame.class, "setDefaultLookAndFeelDecorated", Boolean.TYPE, Boolean.TRUE); //主窗体样式
Methods.invokeStatic(JDialog.class, "setDefaultLookAndFeelDecorated", Boolean.TYPE, Boolean.TRUE); //子窗体样式
}
catch (NoSuchMethodException e)
{
e.printStackTrace();
}
}
try
{
UIManager.setLookAndFeel("ch.randelshofer.quaqua.QuaquaLookAndFeel");
}
catch (Exception e) {}
Runnable doCreateShowGUI = new Runnable() {
@Override
public void run() {
// TODO Auto-generated method stub
createShowGUI();
}
};
SwingUtilities.invokeLater(doCreateShowGUI);
}
}
运行结果如下:
当然,若想更改为其他样式,只需将UIManager.setLookAndFeel();中参数更改即可。
PS:其他皮肤可在http://www.open-open.com/61.htm处下载。