0

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

4

2 回答 2

2

使用当前 LAF 创建一个组件。因此,您可以尝试以下操作:

  1. 将 LAF 设置为系统 LAF
  2. 创建 JFileChooser
  3. 将 LAF 重置为 Nimbus

不确定这是否会导致文件选择器出现任何问题。

于 2013-05-05T22:51:12.830 回答
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文件添加到您的类路径。你可以在这里下载:下载

如果您对使用此文件选择器不感兴趣,请查看此示例。

于 2013-05-05T23:11:23.677 回答