JFileChooser

I want to use the JFileChooser component to display the files in a particular directory, but I need to implement a few things.

1. Should not allow the user to browse through the file system. It should just display a particular location in the filesystem.

2. And is it possiblenot to display the directory namethe look in field in the UI.

The reason I want to do this is, I don't want the user to know the location or the directory name that the file he wants to open is in.

thanks

[530 byte] By [seemamma] at [2007-10-2 5:45:33]
# 1
You might have a go at creating your own FileSystemView and plugging that into the file chooser
tjacobs01a at 2007-7-16 1:55:26 > top of Java-index,Desktop,Core GUI APIs...
# 2
How do I do that?
seemamma at 2007-7-16 1:55:26 > top of Java-index,Desktop,Core GUI APIs...
# 3
This posting should get you started: http://forum.java.sun.com/thread.jspa?forumID=57&threadID=636739
camickra at 2007-7-16 1:55:26 > top of Java-index,Desktop,Core GUI APIs...
# 4
Thank you for the example. I'm working on Linux ...should this be of any concern?
seemamma at 2007-7-16 1:55:26 > top of Java-index,Desktop,Core GUI APIs...
# 5
This question is a repeat of my first posting And is it possible not to display the directory name the look in field in the UI in the JFileChooser
seemamma at 2007-7-16 1:55:26 > top of Java-index,Desktop,Core GUI APIs...
# 6
Use a JList and populate the JList with File.list(...) data.
camickra at 2007-7-16 1:55:26 > top of Java-index,Desktop,Core GUI APIs...
# 7

> is it possible not to display the directory name the look in field in the UI in the JFileChooser

this works on win98SE, but the Jlist is a simpler way to go.

import java.awt.*;

import javax.swing.*;

class Testing extends JFrame

{

int count = 0;

public Testing()

{

setLocation(200,300);

setDefaultCloseOperation(EXIT_ON_CLOSE);

JFileChooser fc = new JFileChooser(".");

hideCombo(fc.getComponents());

fc.showOpenDialog(this);

}

public void hideCombo(Component[] comp)

{

for(int x = 0; x < comp.length; x++)

{

if(comp[x] instanceof JPanel) hideCombo(((JPanel)comp[x]).getComponents());

else if(comp[x] instanceof JComboBox && count == 0)

{

((JComboBox)comp[x]).setVisible(false);

count++;

}

else if(comp[x] instanceof JLabel && ((JLabel)comp[x]).getText().equals("Look In:"))

{

((JLabel)comp[x]).setVisible(false);

}

}

}

public static void main(String[] args){new Testing().setVisible(true);}

}

Michael_Dunna at 2007-7-16 1:55:26 > top of Java-index,Desktop,Core GUI APIs...
# 8

The example worked great ! but I added this one line of code to the exisitng example

import java.awt.*;

import javax.swing.*;

class Testing extends JFrame

{

int count = 0;

public Testing()

{

setLocation(200,300);

setDefaultCloseOperation(EXIT_ON_CLOSE);

JFileChooser fc = new JFileChooser("/etc/opt/eternal/duration");

hideCombo(fc.getComponents());

fc.showOpenDialog(this);

}

public void hideCombo(Component[] comp)

{

for(int x = 0; x < comp.length; x++)

{

if(comp[x] instanceof JPanel)

hideCombo(((JPanel)comp[x]).getComponents());

else if(comp[x] instanceof JComboBox && count == 0)

{

((JComboBox)comp[x]).setVisible(false);

count++;

}

else if(comp[x] instanceof JLabel && ((JLabel)comp[x]).getText().equals("Look In:"))

{

((JLabel)comp[x]).setVisible(false);

}

else if(comp[x] instanceof JButton && ((JButton)comp[x]).getText().equals(null))

{

((JButton)comp[x]).setVisible(false);

}

}

}

public static void main(String[] args){new Testing().setVisible(true);}

}

This is the error

Exception in thread "main" java.lang.NullPointerException

at Testing.hideCombo(Testing.java:30)

at Testing.hideCombo(Testing.java:20)

at Testing.hideCombo(Testing.java:20)

at Testing.<init>(Testing.java:12)

at Testing.main(Testing.java:36)

thanks in advance.

seemamma at 2007-7-16 1:55:26 > top of Java-index,Desktop,Core GUI APIs...