Problem with JFileChooser.getCurrentDirectory()

Hi @ all,

I have currently a Problem with the JFileChooser's Method "get CurrentDirectory().

I have overwritten the method approveSelection:

void approveSelection(){

System.out.println(chooser.getCurrentDirectory());

}

Now, the problem is...I get the Path not with the Current Directoy, but with the Parent of the Current Directoy!

Example: Current Directoy is: C:/Parent/Current

The selected Path is: C:/Parent

Thank you in advance,

Gab

[506 byte] By [Gaba] at [2007-10-1 23:31:57]
# 1
[url http://java.sun.com/docs/books/tutorial/uiswing/components/filechooser.html]How to Use File Choosers[/url]
camickra at 2007-7-15 14:14:46 > top of Java-index,Desktop,Core GUI APIs...
# 2

Thank you, but it does not really solve my problem. There is no example with the getCurrentDirectory() Method, and I tried the example code they give on the tutorial and I have extended it to get the current Directory..but nothing, the program gives me the parent of the Current Directory...

Thank you in advance for some Help!

Gab

Gaba at 2007-7-15 14:14:46 > top of Java-index,Desktop,Core GUI APIs...
# 3
The getCurrentDirectory() method returns a File object. So look at the File class to see if any method there gives you what you want. If you can't find anything then look at the String class. You can always extract the data you need from the String.
camickra at 2007-7-15 14:14:46 > top of Java-index,Desktop,Core GUI APIs...
# 4
I will have a look with the String Class. But I don't aspect a lot, because I tried it already with File. The methods getPath() and getAbsolutePath() bring the same result as the getCurrentDirectory() does...
Gaba at 2007-7-15 14:14:46 > top of Java-index,Desktop,Core GUI APIs...
# 5
JFileChooser.setFileSelectionMode lets you set the JFileChooser to select directories, which it does not do by default.
FuzzyOniona at 2007-7-15 14:14:46 > top of Java-index,Desktop,Core GUI APIs...
# 6
I know this, and I already set it...but the problem is not to choose a directory, the problem is to get his truly Path, because the getCurrentDirectory() Method returns me the parent directory and the current Directory...
Gaba at 2007-7-15 14:14:46 > top of Java-index,Desktop,Core GUI APIs...
# 7
I can't believe you've wasted 4 days over this.Read the String API and extract whatever part of the String you want. There's all kinds of methods there to help you, indexOf, substring...
camickra at 2007-7-15 14:14:46 > top of Java-index,Desktop,Core GUI APIs...
# 8

I'm not wasting all the time over this problem, because i'm working on other things, but this is a problem I will have to solve, and it is better to know the solution ;)

I think you don't understand my problem. I get a Path from the getCurrentDirectory() Method, but it is "incomplete". The truly Current Directoy doesn't appear..just until his Parent Directory. And something like substring or something else from the String Class wouldn't really Help, I think.

Gaba at 2007-7-15 14:14:46 > top of Java-index,Desktop,Core GUI APIs...
# 9

> I think you don't understand my problem. I get a Path from the getCurrentDirectory() Method, but it is "incomplete".

Your right I don't understand your problem. However I think it goes back to my original suggestion to read the tutorial to which you responded:

> There is no example with the getCurrentDirectory() Method

Thats because you should be using the getSelectedFile() method, which is what the tutorial uses.

camickra at 2007-7-15 14:14:46 > top of Java-index,Desktop,Core GUI APIs...