将UIManager中的FileChooserUI属性设置为系统的

时间:2013-05-05 22:47:30

标签: java swing look-and-feel jfilechooser uimanager

我想让我的JFileChooser使用系统的LookAndFeel,但我的其他组件使用Nimbus。由于每个平台都提供不同的FileChooserUI,我如何将UIManager中的FileChooserUI属性设置为系统的LookAndFeel?

2 个答案:

答案 0 :(得分:2)

使用当前LAF创建组件。所以你可以尝试类似的东西:

  1. 将LAF设置为系统LAF
  2. 创建JFileChooser
  3. 将LAF重置为Nimbus
  4. 不确定是否会导致文件选择器出现任何问题。

答案 1 :(得分:0)

如果您使用的是Windows,则可以使用Windows文件选择器:

import org.eclipse.swt.*;
import org.eclipse.swt.widgets.*;

public class FileSelection {


    public static String getPath(){
        String path =null;
        Display display = new Display ();
        Shell shell = new Shell (display);
        // Don't show the shell.
        //shell.open ();  
        FileDialog dialog = new FileDialog (shell, SWT.OPEN | SWT.MULTI);
        path=dialog.open();
        shell.close();
        while (!shell.isDisposed ()) {
            if (!display.readAndDispatch ()) display.sleep ();
        }
        display.dispose ();
        return path;
    }
} 

getPath()将返回所选文件的直接路径,但请注意,您必须下载org.eclips.swt包并将.jar文件添加到类路径中。 您可以在此处下载:Download

如果您对使用此filechooser感兴趣,请Check this example.