简体   繁体   English

如何创建类似于默认窗口框的文件选择器?

[英]How to create file choosers similar to default windows boxes?

I want to create save and open dialogue box using Java Swing JFileChooser , but when I created it shows like first image:我想使用 Java Swing JFileChooser创建保存和打开对话框,但是当我创建它时,它显示为第一张图像:

But I want to create dialogue boxes like windows default dialogue boxes like in image 2:但我想创建像 Windows 默认对话框一样的对话框,如图 2 所示:

For the best user experience of the file chooser, offer the file chooser in the default look-and-feel for the OS.为了获得文件选择器的最佳用户体验,请以操作系统的默认外观提供文件选择器。

try {
    UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
} catch (Exception ex) {
    ex.printStackTrace();
}
JFileChooser jfc = new JFileChooser();
jfc.showOpenDialog(null);

Windows appearance窗户外观

You have 2 choices你有2个选择

  1. You could use java.awt.FileDialog instead.您可以改用 java.awt.FileDialog。 This would probably solve your issue on windows.这可能会解决您在 Windows 上的问题。 I don't know if you need an fd to look like the windows fd on all platforms我不知道你是否需要一个 fd 在所有平台上看起来都像 windows fd

  2. You can make your own JDialog, add a JFileChooser to it (on the right), and replicate the buttons on the left.您可以创建自己的 JDialog,向其中添加 JFileChooser(在右侧),然后复制左侧的按钮。

首先你需要安装最新版本的你的 NetBeans

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

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