Wrox Home  
Search P2P Archive for: Go

  Return to Index  

pro_java thread: Setting JFileChooser's home directory in signed applet.


Message #1 by "Seo, Min-Koo" <4baf@d...> on Tue, 13 Nov 2001 11:11:00 +0900 (KST)
Hi. 

I made a applet which uses "MS SDK for java 4.0" for applet signing. 
I used JFileChooser to show multiple file selection enabled file dialog. 
I succeed in multiple file selection, but a problem still exists. 
When I call showDialog of JFileChooser in my applet, it open the 
'c:\winnt\java' by default. 

I want to make my JFileChooser open the "My Document" folder of
windows system and set the home directory(the directory which is opended
when I press the home icon in the file dialog) to "My Documents" folder.

First of all, I made custom FileSystemView class.

class WindowFileSystemView extends FileSystemView {
	public WindowFileSystemView() {
		super();
	}


	public File[] getRoots() {
		File[] drives = new File[26];
		char driveIterator = 'C';

		for ( ; driveIterator <= 'C' ; driveIterator ++ ) {
			drives[driveIterator - 'A'] = new File(String.valueOf(driveIterator) + ":");
		}

		return drives;
	}

	/** Do not call this.
	*/
	public File createNewFolder(File containingDir) {
		return null;
	}

	public boolean isHiddenFile(File file) {
		return false;
	}

	public boolean isRoot(File file) {
		return file.getAbsolutePath().endsWith("\\");
	}

	public File getHomeDirectory() {
		return new File("C:\\");
	}
	}


I opened the filedialog as follows :

JFileChooser fileChooser = new JFileChooser("c:\\", new WindowSystemView());

and It did not work. It opened c:\winnt\java. So, I tried to set the system properties
using the following code :

public void init() {
	m_Files = new Vector();

	Properties envProperties = System.getProperties();
		if ( envProperties.getProperty("os.name").equals("Windows 2000") ) {
			envProperties.put("user.home","C:\\Documents and Settings\\" + System.getProperty("user.name") + "\\My Documents");
		}
	}
}


and I opend the JFileChooser using the following code : 

JFileChooser fileChooser = new JFileChooser(new WindowFileSystemView()); 

It also did not work.

How can I solve this problem?



-------------------------------------------------
DreamWiz Free Mail @ http://www.dreamwiz.com/
DreamSearch Click the world!!! http://search.dreamwiz.com/



  Return to Index