The following code pops up a file chooser for the user's home directory that sees only .jpg and .gif images:
JFileChooser chooser = new JFileChooser(); FileNameExtensionFilter filter = new FileNameExtensionFilter( "JPG & GIF Images", "jpg", "gif"); chooser.setFileFilter(filter); int returnVal = chooser.showOpenDialog(parent); if(returnVal == JFileChooser.APPROVE_OPTION) { System.out.println("You chose to open this file: " + chooser.getSelectedFile().getName()); }
Warning: Swing is not thread safe. For more information see Swing's Threading Policy. @beaninfo attribute: isContainer false description: A component which allows for the interactive selection of a file. @author Jeff Dinkins
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|