How to use the default File Chooser for the operating system? java

只愿长相守 提交于 2019-12-17 15:56:40

问题


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?

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?


回答1:


Use the old java.awt.FileDialog instead:

new java.awt.FileDialog((java.awt.Frame) null).setVisible(true);



回答2:


You can try using JFileChooser but setting the look and feel to be the platform look and feel:

    try {
        UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
    }catch(Exception ex) {
        ex.printStackTrace();
    }

And that would make all the swing components look nicer!




回答3:


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:

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.




回答4:


The SWT components have always looked the same styles that are in the running OS. You can see some examples:

  • File Dialog Example : Dialog « SWT JFace Eclipse « Java
  • eclipse.platform.swt.git - Eclipse SWT

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.



来源:https://stackoverflow.com/questions/10745198/how-to-use-the-default-file-chooser-for-the-operating-system-java

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!