Hi all,
just got a small query regarding JFileChooser.
i want the user to restrict only to select .jar files . so i used
JFileChooser fileChooser = new JFileChooser("Select a jar file...");
JarFilter1 jFilter = new JarFilter1( "jar", "Only Jars" );
fileChooser.setFileFilter(jFilter);
FileFilter allfileFilter = fileChooser.getAcceptAllFileFilter();
fileChooser.removeChoosableFileFilter(allfileFilter);
The jarFilter is just like this
public class JarFilter1 extends FileFilter {
String m_desc = null;
String m_ext = null;
public JarFilter1(String m_ext, String m_desc) {
this.m_ext = m_ext;
this.m_desc = m_desc;
}
public boolean accept ( File f ) {
if ( f == null )
return false;
if ( f.isDirectory () )
return true;
return f.getName().toLowerCase().endsWith(m_ext);
}
public String getDescription () {
return m_desc;
}
}
int returnVal = fileChooser.showOpenDialog(this);
it shows only directories and jar files, that is fine..
but when i type sample.class or *.class in the filename text box of the dialog, *.class filter gets added to the combo box, so i can select the class file and press ok. and this file is returned back to me..
but i dont want the user to get out of the open dialog until he selects a .jar file...could you please let me know how could this be possible???
thank you