java 如何使用操作系统的默认文件选择器?爪哇
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/10745198/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to use the default File Chooser for the operating system? java
提问by mattbdean
I was just wondering: how does Gmail use the Windows/Mac file chooser to upload files? Is there any way to do this in Java?
我只是想知道:Gmail 如何使用 Windows/Mac 文件选择器上传文件?有没有办法在 Java 中做到这一点?
Personally, I don't like the way that the JFileChooser
looks like, and I thought it would be better for my users to be able to use something that they're more used to. Tips anyone?
就个人而言,我不喜欢JFileChooser
看起来的方式,我认为让我的用户能够使用他们更习惯的东西会更好。提示任何人?
回答by Mattias Isegran Bergander
Use the old java.awt.FileDialog instead:
使用旧的 java.awt.FileDialog 代替:
new java.awt.FileDialog((java.awt.Frame) null).setVisible(true);
回答by Juan Alberto López Cavallotti
You can try using JFileChooser but setting the look and feel to be the platform look and feel:
您可以尝试使用 JFileChooser 但将外观设置为平台外观:
try {
UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
}catch(Exception ex) {
ex.printStackTrace();
}
And that would make all the swing components look nicer!
这将使所有摆动组件看起来更好!
回答by Guillaume Polet
GMail is a web application that eventually relies on the browser to show this component. Now a good solution is to use the Native Look&Feel of the system which provides a JFileChooser quite similar to what you show:
GMail 是一个 Web 应用程序,它最终依赖于浏览器来显示这个组件。现在一个好的解决方案是使用系统的 Native Look&Feel,它提供了一个与你展示的非常相似的 JFileChooser:
UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
EDIT: Pulsar's solution is even better since it provides the exact dialog you are looking for. I am not sure that it provides all the features of the JFileChooser.
编辑:Pulsar 的解决方案更好,因为它提供了您正在寻找的确切对话框。我不确定它是否提供了 JFileChooser 的所有功能。
回答by Paul Vargas
The SWTcomponents have always looked the same styles that are in the running OS. You can see some examples:
在SWT组件一直期待是在运行OS一样的风格。你可以看到一些例子:
It was assumed that from version 7 of Java, Swing styles would be more like that of operating systems, but may see it in Java 8.
假设从 Java 7 版本开始,Swing 样式将更像操作系统的样式,但可能会在 Java 8 中看到它。