Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How can I start an open dialog with Filter ?

Status
Not open for further replies.

sergeiY

Programmer
Feb 13, 2003
132
AU
I would like to filter all but let's say ".obj" files from view when my dialog is open and ... I would like to open it in my local folder.

Thank you
 
Here is how you do it:
Code:
      // This sets the default directory
      File f = new File( "c:\" );
      JFileChooser chooser = new JFileChooser(f);

      // This sets the file filter
      myFileFilter filter = new myFileFilter(true); 
      chooser.setFileFilter(filter); 

      if ( chooser.showOpenDialog( parent ) == JFileChooser.APPROVE_OPTION) 
      {
         f = chooser.getSelectedFile(); 
      }

myFileFilter is a class that you create that extends FileFilter. It does the work of eliminating files that don't match what you want.


 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top