Results 1 to 3 of 3
Thread: JFileChooser
- 07-12-2010, 04:24 PM #1
Member
- Join Date
- Jun 2010
- Posts
- 12
- Rep Power
- 0
JFileChooser
I am using JFileChooser to open data files I have created but am unable to find a simple explanation as to how to filter them to a specific file extension type. Can anyone help please?
[code]
{File f = new File(thingsName+".zzz");// set to existing file
chooser.setFileSelectionMode(JFileChooser.FILES_ON LY);
chooser.setSelectedFile(f);
int returnVal=chooser.showOpenDialog(null);
File curFile=new File("");
if (returnVal == JFileChooser.APPROVE_OPTION)//file selected
{ curFile = chooser.getSelectedFile();
System.out.println("File Type= "+curFile);}
[\code]
- 07-12-2010, 04:28 PM #2
Math problems? Call 1-800-[(10x)(13i)^2]-[sin(xy)/2.362x]
The Ubiquitous Newbie Tips
- 07-12-2010, 06:08 PM #3
Member
- Join Date
- Jun 2010
- Posts
- 12
- Rep Power
- 0
After very confusing run round the various Sun samples and Definitions found this VERY simple example of how to implement a filter- so simple compared with all the others
Java: javax.swing.filechooser.FileFilter
Java Code:class SQLfilter extends javax.swing.filechooser.FileFilter { public boolean accept(File f) { return f.isDirectory() || f.getName().toLowerCase().endsWith(".sql"); } public String getDescription() { return "SQL files"; } }//______________ chooser.setFileFilter(new SQLfilter());Last edited by javabarn; 07-12-2010 at 06:11 PM. Reason: quoted zzz not original sql as extension
Similar Threads
-
jfilechooser
By ranadav in forum AWT / SwingReplies: 7Last Post: 06-03-2010, 02:44 PM -
Jfilechooser
By greatmajestics in forum Java 2DReplies: 5Last Post: 03-30-2010, 06:13 PM -
help with JFileChooser
By morgatron in forum New To JavaReplies: 1Last Post: 01-08-2010, 09:00 AM -
JfileChooser Help
By simmi in forum AWT / SwingReplies: 9Last Post: 08-04-2009, 02:24 AM -
how to use JFileChooser
By tommy in forum New To JavaReplies: 1Last Post: 08-06-2007, 08:49 PM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks