Is there a way to make the JFileChooser show the directory string at the top of the dialog just like in Windows? I need it because in that way, the users can paste the value they want instead of traversing the hierarchy every time.
PS: I'd like to avoid custom FileChoosers if possible.
What I want:
What I have:
The best solution would be to use the FileChooser from JavaFX. It has all the features needed to emulate the Windows file dialog.
http://docs.oracle.com/javafx/2/api/javafx/stage/FileChooser.html
Related
In my Java application I am using JFileChooser for choosing files from directory. I would like to select multiple files with dragging mouse over them. By default it's not working, but I enabled multiple selection. I don't know how to do it.
Is there any other way to do it or any other API? Any help will be gladly appreciated.
After searching a lot I found an API namely ,
Native Swing "The DJ Project"
In this API ,there is a class "JFileDialog" this is what i was looking for.This filedialog allows multiple selection with mouse drag and also better than Jfilechooser in the point of look and feel.But before Using this API one must have to add DJNativeSwing.jar , DJNativeSwing-SWT.jar , swt-4.3-win32-win32-x86.jar library to the project build path and also the project should be Run with 32-bit JRE .
see this snippet of code as example from this link : https://dzone.com/articles/native-dialogs-swing-little
I want to use JFileChooser for Windows and FileDialog for Macs in my Java app. I have it already written in JFileChooser, do I need to completely rewrite it to handle the case for Macs (i.e check if the current OS is Mac and reimplement everything using FileDialog) or is there a easier way?
Short answer: yes, you have to reimplement everything.
Long answer: you could try to add an additional abstraction layer on top of everything, e.g. something like MyOpenDialog and MySaveDialog. These classes decide upon the OS whether to use JFileChooser or FileDialog, so you still have to implement it once. But only once, and if you need it in multiple places in your application, you can just use your own classes.
Be aware that FileDialog does not offer all the features of JFileChooser, e.g. offering the user a list of file formats to choose from (FileFilter) is only available for JFileChooser.
I am new to using JTrees in Java. I am kind of in doubt as to how to configure it the way I want. I've been looking around for answers, but either I am not searching right, or maybe it's not possible without extensive coding?
I want to use a JTree to show all files on the computer and update whenever a file is changed/added/created/deleted etc. (Does JTree keep track of this itself?)
Place a check box next to all files that have a Cpp extension.
Some kind of method to get all the files that have had their box checked and pass it to parser I've made.
How would I go about this exactly? I can't really seem to find an easy way to configure the JTree as I please, unless I am completely missing something?
I want to display results of a file search. I want to enable a context menu for a file selection, which will be the system's context menu.
For example, if the user right-clicks a file in Windows - I want to display the popup-menu with the options:
Open
Open with...
Edit
Send to...
Copy
Cut
etc...
And, if possible - this menu will be generated automatically, depending on the operating system.
If that is not possible or too complex - I'd like to at least enable a "Locate on disk" option which will open a Windows Explorer (or its equivalent in other system) in the file's folder and select the file.
The application is written in Java (JDK 7) using SWT.
Take a look at the example of how to use a popup menu:
Snippet131
Once you are in the handleEvent() method you can perform any logic you need in order to add menu items to your context menu.
In order to get platform specific behavior you can use System.getProperty() with a combination of the "os.name", "os.arch", and "os.version" strings in order to determine which platform you are running. Then just use if statements to conditionally add menu items to your menu.
For Windows you can achieve this but you have to call some native COM methods. I did it with native calls, maybe it is possible with JNA. You need the functionality from IContextMenu2.
Then you can extend the SWT Menu class, populate it with QueryContextMenu(), subclass it and handle WM_DRAWITEM, WM_MEASUREITEM, WM_INITMENUPOPUP, WM_MENUSELECT and WM_COMMAND and forward them to IContextMenu2 instance via HandleMenuMsg.
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 implementation of a file chooser?
The AWT FileDialog actually does use the native component, but as with most AWT vs. Swing issues, it's much less flexible and customizable than Swing's JFileChooser. So there's a tradeoff: JFileChooser may have a clunky user interface, but it's usually better for most purposes. If you really want your file choosing dialogs to look and feel like the native ones, though, then you can go with FileDialog.
I know this is a little late, but it may help other users. You can customize the UI of an application to the UI of the OS:
try {
UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
} catch (Exception e) {e.printStackTrace(); }
You can also try XFileDialog. Haven't tried it much yet but looks worth evaluating.
I wrote a wrapper around JavaFX' file chooser if available. If included in your application, you can replace
JFileChooser fileChooser = new JFileChooser();
with
JFileChooser fileChooser = new NativeJFileChooser();
It will then use the native (and modern) file chooser of the underlying platform. Not everything works 100% the same, so make sure to test it afterwards, but most things should go smoothly.
As #htw said use FileDialog if the look and feel is your main concern. By using FileDialog be aware that there a lots of convenience methods that you won't be able to use...
I used VFSJFileChooser few times. It doesn't suffer from the JFileChooser bugs(slow to load because of zip files, windows only), but the interface is not "native".