jfilechooser

Alternative to JFileChooser

旧时模样 提交于 2019-11-27 19:07:07
I've a request to make some changes to a little applet that currently use a JFileChooser. One of the main complaints is that the file chooser is a pain in the ass to use because it behaves differently than the native widget, especially for navigating up to the root level. So, knowing that and all the other issue JFileChooser suffer (like the zip file caching on windows...), I was wondering that a viable alternative exists in the java world. Of course, there is SWT that use the native widget, but increasing the applet size by 25 is not really an option. So, is there a better pure java

JFileChooser on OS X

放肆的年华 提交于 2019-11-27 18:23:59
问题 JFileChooser looks nothing like the native widget. I seem to remember reading some hack to get it look like the native widget but searching for it know i can't seem to find it again i came across posts that suggest using java.awt.FileChooser but that class does not seem to be in the distribution. How can i make JFileChooser make look like the native widget? 回答1: Take a look at this page. It goes through a lot of UI tweaks, but the third one is most relevant: "Using the JFileChooser to get Mac

Windows native File chooser in java

我的梦境 提交于 2019-11-27 17:02:42
问题 Apparently, there are (at least?) two different native File choosers on Windows (10). There is this one, which is used by JFileChooser and other programs: And there is that one, for example used by Chrome: I like it much more than the first one because: You can directly enter your file path at the top Your can search the folder The direct access on the left contains the whole file tree How do I get it in Java? 回答1: Use the JavaFX library FileChooser fileChooser = new FileChooser(); fileChoose

JFileChooser.showSaveDialog(…) - how to set suggested file name

大憨熊 提交于 2019-11-27 12:17:11
The JFileChooser seems to be missing afeature: a way to suggest the file name when saving a file (the thing that usually gets selected so that it would get replaced when user starts typing). Is there a way around this? If I understand you correctly, you need to use the setSelectedFile method. JFileChooser jFileChooser = new JFileChooser(); jFileChooser.setSelectedFile(new File("fileToSave.txt")); jFileChooser.showSaveDialog(parent); The file doesn't need to exist. EDIT: If you pass a File with an absolute path, JFileChooser will try to position itself in that directory (if it exists).

How to “Open” and “Save” using java

旧街凉风 提交于 2019-11-27 12:01:15
I want to make an "Open" and "Save" dialog in java. An example of what I want is in the images below: Open: Save: How would I go about doing this? Mike Clark I would suggest looking into javax.swing.JFileChooser Here is a site with some examples in using as both 'Open' and 'Save'. http://www.java2s.com/Code/Java/Swing-JFC/DemonstrationofFiledialogboxes.htm This will be much less work than implementing for yourself. You want to use a JFileChooser object. It will open and be modal, and block in the thread that opened it until you choose a file. Open: JFileChooser fileChooser = new JFileChooser()

adjust selected File to FileFilter in a JFileChooser

删除回忆录丶 提交于 2019-11-27 06:43:09
问题 I'm writing a diagram editor in java. This app has the option to export to various standard image formats such as .jpg, .png etc. When the user clicks File->Export, you get a JFileChooser which has a number of FileFilter s in it, for .jpg , .png etc. Now here is my question: Is there a way to have the extension of the default adjust to the selected file filter? E.g. if the document is named "lolcat" then the default option should be "lolcat.png" when the png filter is selected, and when the

JFileChooser select directory but show files

回眸只為那壹抹淺笑 提交于 2019-11-27 06:37:49
问题 I feel like there should be a simple way to do this but I can't figure it out. I have a JFileChooser that allows the user to select directories. I want to show all the files in the directories to give the user some context, but only directories should be accepted as selections (maybe the Open button would be disabled when a file is selected). Is there an easy way of doing this? 回答1: Override the approveSelection() method. Something like: JFileChooser chooser = new JFileChooser( new File(".")

Alternative to JFileChooser

不想你离开。 提交于 2019-11-27 04:21:34
问题 I've a request to make some changes to a little applet that currently use a JFileChooser. One of the main complaints is that the file chooser is a pain in the ass to use because it behaves differently than the native widget, especially for navigating up to the root level. So, knowing that and all the other issue JFileChooser suffer (like the zip file caching on windows...), I was wondering that a viable alternative exists in the java world. Of course, there is SWT that use the native widget,

JFileChooser filters

烈酒焚心 提交于 2019-11-27 01:51:28
I am putting a JFileChooser in my program, but that only takes images. So I decided to add filters: Code import javax.swing.*; public class fileChooser { public static void main(String[] args) { JPanel panel = new JPanel(); final JFileChooser fc = new JFileChooser(); int file = fc.showOpenDialog(panel); fc.addChoosableFileFilter(new ImageFilter()); fc.setAcceptAllFileFilterUsed(false); } } I got that straight from the Java tutorials. But Eclipse underlines the following as an error: fc.addChoosableFileFilter(new ImageFilter()); fc.setAcceptAllFileFilterUsed(false); Any suggestions? I am

How do I restrict JFileChooser to a directory?

眉间皱痕 提交于 2019-11-26 17:49:44
I want to limit my users to a directory and its sub directories but the "Parent Directory" button allows them to browse to an arbitrary directory. How should I go about doing that? McDowell You can probably do this by setting your own FileSystemView . Incase anyone else needs this in the future: class DirectoryRestrictedFileSystemView extends FileSystemView { private final File[] rootDirectories; DirectoryRestrictedFileSystemView(File rootDirectory) { this.rootDirectories = new File[] {rootDirectory}; } DirectoryRestrictedFileSystemView(File[] rootDirectories) { this.rootDirectories =