Selecting multiple files with mouse drag in JFileChooser - java

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

Related

how can i make a program take any path itself without making browse

Is there any java code or an algorithm can use it to make an application (wrote in netbeans) take any path itself for any text or folder etc... , without making browse or fileChooser? ( for example : like winrar , it can take the path itself to make compress for the text that click on ).
I think what you mean is the "right-click integration" of WinRAR:
If so, you can do that with any program. How this is implemented depends on your operating system:
For Windows, Add a Registry Key
For Mac OSX, Add it in the system-settings
For Linux, there is no "one fits all" solution, as it depends on the file-browser you're using (Nautilus, Thunar, etz). Have a look at their documentation.
These are just some results that came up by searching for [operating-system] right click integration. Go see for yourself.

How to select multiple folders and files in Javafx2?

I am working on javafx 2. but there is no feature of multiple folders and files available on the filechooser.
There is the Directory chooser but it selects only one folder. How can i solve this problem. Please give me any suggestion?
JavaFX supports single and multiple file dialogs:
http://docs.oracle.com/javafx/2/api/javafx/stage/FileChooser.html
and single directory dialog:
http://docs.oracle.com/javafx/2/api/javafx/stage/DirectoryChooser.html
There was a special RFE for this : https://bugs.openjdk.java.net/browse/JDK-8101526.
There is a special RFE for multiple directories chosign, you can wait, until it will be fixed : https://bugs.openjdk.java.net/browse/JDK-8091403, also, you can vote it up, for it to be fixed with higher priority
We can use JFileChooer of Swing component. But then its give error like Headless something. So remove this error by following steps.
1) Initialised all component of swing before javafx.
2) use System.setProperty and set Headless false .
Then jfilechooser works. Thanks to all.

Drag And Drop from Java Swing Application to Windows Explorer

I have question about Drag And Drop in Java.
I was able to to implement drag and drop files from Windows Explorer to Swing application.
Now I need to oposite direction.
I have JTable which contains Column with object type File. I just need to detect which file (files) are dragged and where in Windows Explorer.
Thanks in advance.
I was working with java<->native DnD couple of years ago and my findings were something like below.
If you need to know to which folder dragged files were dropped (for example) to write them out from database: I am quite unsure this is possible. The best you could do is precreating files on drag start, passing correct file references to drop target app, and hoping that explorer default drop handler does what you need. I suspect that on drag-out of java app you have no control and no callbacks on the drop target application (until you have own fancy super-hook somewhere on the explorer side).
Not sure your scenario is as bad as mine was; the feature was not critical and we deferred it...
I guess, all you need can be found here

DragNDrop from Java to Windows Explorer

I want to create an application in Java that lists a directory and add drag and drop support to it for copying files from that directory to the explorer window opened and vice-versa(Windows system).
While adding support to drag and drop from windows explorer to the java application is quite easy, it kind of eludes me how to do it when the action starts from the java application and ends in explorer.
I tried searching google and SO, but to no avail.
Any pointers, directions, snippets of codes or pseudocodes will be appreciated.
So, is it possible to drag from a java application and transfer data to a drop target in a native application? If yes (it should be), can you point me in the right direction?
Yes, what you have to do is set the mime type on the transferable, and set the accepted actions (i.e. copy, move, etc) as well as the default action (it sounds like a copy action for what you are trying to do). This class is the transfer handler, which is what is used to handle DnD in Swing.
Just use the fileListFlavour DataFlavour and File drag'n drop will "just work" in both directions.
I'm sure you found the section on drag n drop in the java tutorial.
Book: Swing Hacks
Hack # 65
That's your answer :)

How to launch the default (native) application for a given file from Java?

I am displaying a list of files; i.e. xls, doc, pdf, odt etc., in my Java application (Eclipse RCP). When the user clicks on the file, I want to launch the appropriate (according to what the OS thinks) native application, just like it happens in Windows Explorer or the Finder.
And while I am here: It would be nice to also display the same icons that Finder or Explorer use for the different file types.
Is there a library or Eclipse plugin for this?
What you want is java.awt.Desktop:
Desktop.getDesktop().open( file );
I have found an API in Eclipse's SWT now that seems to do the trick:
org.eclipse.swt.program.Program "provides access to facilities for discovering operating system specific aspects of external program launching."
It has methods to find the program for a given file extension, get the program's icon, and even launch the program.
Sounds like you're after the Java Activation Framework ("JAF"). This API lets you determine what files are and what actions you can do on them. Or alternatively the Java Desktop Integration Component ("JDIC"). JDIC allows you to create and no doubt query file associations.
Both projects seem to be in a semi-abandoned state howeer (sigh). But that's par for the course for Sun these days. Only other thing I know of is some Windows specific third party library that's based on JNI called Winpack. It does a bunch of other things too.
You can get the associated icon using the FileSystemView class (Java 1.4+).

Categories