使用FileDialog和JFileChooser时,在Mac OS上选择文件看起来有所不同

时间:2015-06-01 20:46:40

标签: java jfilechooser

目前我的应用程序是使用JFileChooser编写的,但我更喜欢选择文件时的FileDialog外观。有没有改变JFileChooser for Mac OS X的外观和感觉,使它看起来像FileDialog?

1 个答案:

答案 0 :(得分:-1)

您可以使用UIManager和Swing Utilities更改某些对象的外观,甚至还可以恢复原始外观。

import javax.swing.plaf. *;    
import javax.swing.*;

public class TestClass {
public static void main(String[] args) {
 JFrame Frame = new JFrame();
JFileChooser file = new JFileChooser();
LookAndFeel Revert = UIManager.getLookAndFeel();
LookAndFeel LF = UIManager.getSystemLookAndFeelClassName(); // Mac OS
try{
UIManager.setLookAndFeel(LF);
SwingUtilities.updateComponentTreeUI(file); // Changes file to current look and feel
UIManager.setLookAndFeel(Revert); // Remove this is you don't want to revert.
}
catch (Exception Fail) {
System.out.println(Fail);
}

}
}