Results 1 to 3 of 3
Thread: JFileChooser restriction
- 03-13-2011, 07:31 PM #1
JFileChooser restriction
In my Java program, I use a JFileChooser to bring in a file for processing. How can I restrict the JFileChooser to only accept a file of type .txt, or do a System.exit(1) otherwise. Or better yet, can I set it up so that the JFileChooser only displays .txt files in the window.
Last edited by sehudson; 03-13-2011 at 07:40 PM.
- 03-13-2011, 08:08 PM #2
You can set a file filter such as:
SusannaJava Code:private class TxtFileFilter extends FileFilter{ public boolean accept(File file){ if(file.isDirectory()) return true; String fname = file.getName(); return fname.endsWith("txt"); } public String getDescription(){ return "txt file"; } }
- 03-14-2011, 03:21 AM #3
Similar Threads
-
4 digit restriction
By GTM in forum Java AppletsReplies: 3Last Post: 12-28-2010, 02:26 AM -
Access Restriction error
By kraut in forum New To JavaReplies: 2Last Post: 06-19-2010, 01:29 AM -
Access Restriction error
By kraut in forum EclipseReplies: 0Last Post: 06-19-2010, 01:07 AM -
Access restriction: Class is not accessible due to restriction on required
By kiranblighty in forum EclipseReplies: 7Last Post: 02-19-2010, 11:03 AM -
Error: Access restriction
By livnihai in forum EclipseReplies: 1Last Post: 11-25-2009, 06:53 PM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks