1

我有一个 Swing 应用程序,我想使用 Windows7/Vista 风格的 FileDialogs,并找到了一个将 SWT 与 swing 结合使用的合理解决方案: Swing 是否支持 Windows 7 风格的文件选择器?

但是,现在我试图让这个对话框只接受目录(“选择文件夹”按钮而不是“打开”按钮)。

不想使用典型的 DirectoryDialog:

在此处输入图像描述



我想使用左侧的收藏夹、顶部的地址栏以及选择文件夹的能力的对话框:

在此处输入图像描述

有谁知道如何做到这一点?

非常感谢您的回复。

4

2 回答 2

0

Baz already said it: It is not possible to get this dialog using SWT. To answer your question about other frameworks: I believe there are plenty, for example you could use Jide. You do not get the dialog you want, but at least you get an enhanced version (FolderChooser) with few advantages:

  • Convenience-Buttons (Desktop, My Documents, ...)
  • Delete/Create new directory
  • Address bar

And the best of all this: You get it for free, cause it's in the "Common Layer". You can try the FolderChooser by launching the Demo-WebStart-Project.

于 2013-08-05T13:42:22.540 回答
-1

这是一种黑客行为:

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

public class Demo{

    public static void main(String [] args) {
        Display display = new Display();
        Shell shell = new Shell(display);  
        FileDialog dialog = new FileDialog(shell, SWT.OPEN | SWT.MULTI);
        dialog.setFilterPath("c:\\");

        //The extension doen't excist!
        dialog.setFilterExtensions(new String[] {"xyz"});
        //You can also use " ";

        dialog.open();
        shell.close();
        while (!shell.isDisposed()) {
            if (!display.readAndDispatch()) display.sleep();
        }
        display.dispose();
    }
}

我试过了,我觉得,效果很好!

于 2018-01-10T17:55:06.743 回答