[英]Java Swing JFileChooser filter does not work for sqlite
I copied and modified an example from here .我从这里复制并修改了一个示例。 I changed it for sqlite.
我将其更改为 sqlite。 I am looking at a directory with.app, .jar, and.sqlite files.
我正在查看包含 .app、.jar 和 .sqlite 文件的目录。 The.jar files are grayed out, but.sqlite and.app files are selectable.
.jar文件是灰色的,但是.sqlite和.app文件是可选的。 Why is the filter not making the.app files not selectable?
为什么过滤器不使 .app 文件不可选? I only want.sqlite to be selectable.
我只想选择.sqlite。 I am running this on Mac OS X.
我在 Mac OS X 上运行它。
package org.todivefor.filechooser4;
import javax.swing.JFileChooser;
import javax.swing.filechooser.FileNameExtensionFilter;
import javax.swing.filechooser.FileSystemView;
public class FileChooser4 {
public static void main(String[] args) {
JFileChooser jfc = new JFileChooser(FileSystemView.getFileSystemView().getHomeDirectory());
jfc.setDialogTitle("Select DB");
jfc.setAcceptAllFileFilterUsed(false);
FileNameExtensionFilter filter = new FileNameExtensionFilter("SQLite DB", "sqlite");
jfc.addChoosableFileFilter(filter);
int returnValue = jfc.showOpenDialog(null);
if (returnValue == JFileChooser.APPROVE_OPTION) {
System.out.println(jfc.getSelectedFile().getPath());
}
}
}
EDIT:编辑:
First, I don't think I understood how this was to work.首先,我认为我不明白这是如何工作的。 I thought by specifying a filter with sqlite, I would not see anything without an.sqlite extension.
我想通过使用 sqlite 指定一个过滤器,如果没有一个.sqlite 扩展名,我将看不到任何东西。 In my testing, I find I can see files of all extensions, but can only select those with.sqlite.
在我的测试中,我发现我可以看到所有扩展名的文件,但只能看到 select 那些带有.sqlite 的文件。 I tried my code above on both Mac OS X and Windows and saw different results.
我在 Mac OS X 和 Windows 上尝试了上面的代码,看到了不同的结果。 On Windows, I saw both.app and.sqlite files, but I could only select.sqlite files.
在 Windows 上,我看到了 both.app 和 .sqlite 文件,但我只能看到 select.Z786D348E95442E4287 文件。 On Mac OS X, I saw both.app and.sqlite files and could select either.
在 Mac OS X 上,我看到了 .app 和 .sqlite 文件,也可以看到 select 文件。 I am not sure why this is, but has something to do with look and feel.
我不确定这是为什么,但与外观和感觉有关。 On both Windows and Mac, I do not specify a look and feel, so I guess I get the default.
在 Windows 和 Mac 上,我没有指定外观,所以我想我得到了默认值。 On Windows, the.app files appear as folders.
在 Windows 上,.app 文件显示为文件夹。 Whereas on Mac, they appear as files (still don't know why they are selectable).
而在 Mac 上,它们显示为文件(仍然不知道为什么它们是可选的)。 The application where I am using this, I control the L&F, and It works the way I expect, except for the Mac OS X L&F where I can select a.app extension file.
我使用它的应用程序,我控制 L&F,它以我期望的方式工作,除了 Mac OS X L&F,我可以 select a.app 扩展文件。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.