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]

> 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);}
}
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.