首先去下載蘋果風格的jar包。quaqua.jar 下載地址:https://quaqua.dev.java.net/
swing的界面通常是通過UIManager.setLookAndFeel來控制的。
設置UIManager的代碼:
public static void main(String args[]){
System.setProperty("Quaqua.tabLayoutPolicy", "wrap");
if (!System.getProperty("os.name").toLowerCase().startsWith("mac")) {
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) {
}
DBConnFrame f = new DBConnFrame();
f.setTitle("數據庫連接嚮導");
f.setSize(600, 400);
f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);//關閉窗口事件
f.setVisible(true);
}
就這樣吧!看風格附圖如下