简体   繁体   English

如何设置FileDialog的最小/最大大小? -SWT-Java

[英]How to set minimum-/maximum-size of FileDialog? - SWT - Java

I hava a DirectoryDialog like this: 我有一个这样的DirectoryDialog

private static void openFiles() {
    Display display = new Display();
    Shell shell = new Shell(display);
    DirectoryDialog directoryDialog = new DirectoryDialog(shell, SWT.OPEN | SWT.MULTI);
    directoryDialog.setFilterPath("c:\\");
    Files[] files = new File(directoryDialog.open().listFiles());
    shell.close();
    while (!shell.isDisposed()) {
        if (!display.readAndDispatch()) display.sleep();
    }
    display.dispose();
}

And how`can I now for example set the minimum size? 我现在如何例如设置最小尺寸?

I've tryed out shell.setMinimumSize(500, 500) , but it didn't work! 我已经尝试过shell.setMinimumSize(500, 500) ,但是没有用!

You cannot set the size of a DirectoryDialog . 您不能设置DirectoryDialog的大小。 The size and position are determined by the OS. 大小和位置由操作系统确定。

Related: https://www.eclipse.org/forums/index.php/t/142845/ 相关: https : //www.eclipse.org/forums/index.php/t/142845/


If you absolutely need to enforce a minimum size, you will need to implement your own. 如果您绝对需要执行最小大小,则需要实现自己的大小。 For custom dialogs I would recommend taking a look at a JFace Dialog and its subclasses. 对于自定义对话框,我建议您看一下JFace Dialog及其子类。

Here is a good article about SWT and JFace dialogs: http://www.vogella.com/tutorials/EclipseDialogs/article.html#jface-dialogs . 这是一篇有关SWT和JFace对话框的好文章: http : //www.vogella.com/tutorials/EclipseDialogs/article.html#jface-dialogs


I also found a custom directory dialog which is just implemented using a Shell , so you would naturally have full control over size and position: http://esus.com/creating-an-swt-directorydialog/ 我还发现了一个仅使用Shell实现的自定义目录对话框,因此您自然可以完全控制其大小和位置: http : //esus.com/creating-an-swt-directorydialog/

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM