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

我的梦境 提交于 2019-11-27 20:41:42

Use the old java.awt.FileDialog instead:

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

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!

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.

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

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.

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