How JFileChooser finds the Desktop and can browse CIFS(SMB) in windows.
Hello.
I'm currently using serveral methods from FileSystemView used by JFileChooser to detect if a File is a system root, a floppy, or to find the "My Documents" folder under windows.
JFileChooser however is also able to provide a link to the desktop. How do I get that location from Java?
Further more. JFileChooser is able to browse and use resources located on the network using CIFS(SMB). I've searched through JFileChoosers source. But I can't figure out how it does this.
I'm currently writing a Folder synchronization app. As you can see in the screenshot ( http://users.telenet.be/greenhouse/Screenshot-7.png ) I'm trying to integrate the location browser (Look based on the GTK file browser) more into windows. I want my users to be able to browse CIFS just like in the JFileChooser. How do I do this?
The reason I'm writing my own browser is because the GTK one provided in Java is more then lacking. And I can provide browsing for remote resources more easily (like SFTP and SCP)
In short:
*JFileChooser however is also able to provide a link to the desktop. How do I get that location from Java?
*JFileChooser browses and uses CIFS in windows. How do I do this (without a 3th party library) the same way as JFileChooser does it?
Message was edited by:
finalbeta
[1350 byte] By [
finalbetaa] at [2007-11-27 4:43:04]

# 1
public String openFile() throws FileNotFoundException, IOException {
String filename, doc = "";
JFileChooser chooser = new JFileChooser(System.getProperty("user.dir");
int reply = chooser.showOpenDIalog(null);
if(reply == JFileChoose.APPROVE_OPTION) {
doc = openFile(chooser.getSelectedFile().getAbsolutePath());
}
return doc;
}
is this what you want?
Message was edited by:
lrngjava
# 2
> > public String openFile() throws
> FileNotFoundException, IOException {
>String filename, doc = "";
> JFileChooser chooser = new
> JFileChooser(System.getProperty("user.dir");
> int reply = chooser.showOpenDIalog(null);
> if(reply == JFileChoose.APPROVE_OPTION) {
> doc =
> openFile(chooser.getSelectedFile().getAbsolutePath())
//-->Dont you mean justdoc =chooser.getSelectedFile().getAbsolutePath()
//as openfile() might confuse the OP
>
> }
> return doc;
> }
>
>
> is this what you want?
>
> Message was edited by:
> lrngjava
# 3
No, that's not it at all. I'm not asking how to use the JFileChooser.
How do I get the path to the users desktop? JFilechooser does it. I want to do it to.
How do I browse the network and use the resources the way JFileChooser does.
As you can see in the screenshot, I'm writing my own kind of file browser. So I need to implement those actions.
# 4
JFileChooser fr = new javax.swing.JFileChooser();
FileSystemView fw=fr.getFileSystemView();
defaultfolder = fw.getDefaultDirectory().getPath();
String desktopfolder;
if(System.getProperty("os.name").startsWith("Windows")){
for(File tmp:fw.getRoots()){
dekstopfolder = tmp.getPath();
}
}
That piece of code gives the path to the desktop folder in Windows. In linux it returns root. (getRoots();) How horrible.
I hope I'm going about this the wrong way. Because this would be an ugly Java API.