How to focus on a folder from java program - java

I am trying to open a folder from java program by using the following java code
Desktop.getDesktop().open(new File("d:\\abc"));
I can successfully opened d:\\abc, now this abc folder is having two sub folders images, and songs now my reuirement is to focus this folder then open it by depending on user given input at run time.
May be tomorrow these sub file names will be changed, but depending on user input i want to focus on corresponding sub folders and open them.
I tried lot of ways in google and stackoverflow also. But I didn't get proper way.

Use a JFileChooser to display the local file system and get the user's selection. Alternatively, add a suitable list or tree selection listener to one of the display components cited here.

You can use Robot class, by using this Robot class you can press key on keyboard programatically.
If user input is
images
then user Robot class to press corresponding key programatically.
Here you can get tutorial on Robot class
http://docs.oracle.com/javase/7/docs/api/java/awt/Robot.html

Related

Extracting all string literals from a java project

There is a big Java project that contains lots of Java and JavaScript classes. We need to translate the app into a foreign language.
What we need to do is:
Right click on a class
Click on Extract Strings button
Display all strings in the file with a check-list structure in a pop-up window
Select the strings we want to save
The unselected ones will be assigned as not-string-literal in order to prevent it from appearing in the list when I try next time.
Click on Ok and the strings are stored in a messages.properties file
We are using Netbeans IDE and a plugin would be wonderful if there is any. Can you advise me on how to do this?

How do I create an area were files dragged into it add the URI to a list?

I am trying to create a program were the user drags a file into an area (currently a JTextArea, but can be another container) and it adds the absolute path of the file to an ArrayList. I am having trouble figuring out how to implement drag and drop of files.
so far I have tried reading some similar questions but they aren't really helping me.
(also this is targeting windows but linux/mac support is an option as well)
Have a look at oracles page about DnD. Basically you can drag everything into your program, should it be a file directly from a native browser or the JFileChooser. What you are dragging is only the path to the file. So you only have to set your JTextAreato accept drops and define how it has to "interpret" the object that was being dropped.
Here is a full blown example.

Java How to prevent user edits of file name in FileChooser OpenFileDialog

I need an Open Dialog File Chooser that opens files for reading only. I want user to only be able to click on a file name to select it with no option to edit the name. Users should be able to browse to other folders, though.
I'm on Ubuntu 10.11 with the latest Java (as of January).
TIA.
This example shows that editable file names is a feature of the FileChooserUI implementation. For example, com.apple.laf.AquaFileChooserUI does not have this capability. The tutorial does not suggest any way that it can be changed, but this FileBrowser may suggest a custom alternative.

Access a file from different Directory

I am working with a Java Application. In this, I must copy a file from source to Multiple Destinations. The destinations are various USB drives. (ie) I'm copying a file for desktop and sending to a number of USB drives. Here, my problem is, I am sending files to all USB drives I attached, now I need to make the files UN-deletable. The undeletable process will be done in a single event. For example once I click the ok button, the Files, which are present in all USB drives are made undeletable. Any idea how to do this.
When copying source file to other files, put the destination File objects in a collection. Then, in the event handler for your 'set read only' button, loop over that collection and call setReadOnly() on each File.
not very sure I understand your question correctly.
maybe you can store the directories and when you click the OK button, you iterate these directories and set them to undeletable one by one?

Pressing save button in JFileChooser opens a folder instead of saving a file

I'm having the following problem with a JFileChooser: I create a save dialog and then when I'm trying to save a file, I'm entering a file name into the field and click "Save". Suppose that the directory, which I try to save my file to, contains a subdirectory, which is named exactly like the entered name. In this case JFileChooser opens it instead of saving my file, and I don't know how to make it save a file instead of opening the directory with the same name.
I tried to do something with the file filters, with approveSelection() and changed UI from Windows to default - nothing helps. How to make JFileChooser stop opening a folder and save the file? Is there some way to modify the behavior of the button or am I just doing something wrong?
Update:
To be clear: I'm not trying to save a file with the same name, I'm just trying to make JFileChooser get the path so I could append an extension to it. However, I checked Word and Photoshop, neither of them is able to do what I request, so I guess I wish to make everything too perfect. But if there's a way to do what I want, I'll still be glad to hear the solution.
Neither Windows nor Linux allow file names and directory names to be the same in the same directory as far as I know. Under Linux of course they can be the same with different case lettering :)

Categories

Resources