Jfilechooser info
HI
I'm using Jfilechooser to open/save files.
I have some question:
1) The filechooser language is italian, now I want to show it with english language...
2) in the save filechooser, i want to save xml files, so I wanna show in the "file name" field something like a "*.xml" string, and I wanna cut the file type filter field (or at least to show only directory and xml file).
How could I do both of them?
tks
GG
[463 byte] By [
lastninjaa] at [2007-10-2 20:20:14]

Create this class
import java.io.File;
/**
* Only shows files of type XML in the JFileChooser to select
* files to be loaded into the application
*/
public class XMLFilter extends javax.swing.filechooser.FileFilter
{
public boolean accept(File file)
{
boolean accept = file.isDirectory();
if (!accept)
{
String suffix = getSuffix(file);
if (suffix != null)
accept = suffix.equals("xml");
}
return accept;
}
private String getSuffix(File file)
{
String s = file.getPath(), suffix = null;
int i = s.lastIndexOf('.');
if (i > 0 && i < s.length() - 1)
suffix = s.substring(i + 1).toLowerCase();
return suffix;
}
public String getDescription()
{
return "XML files(*.xml)";
}
}
Then create a method like 'openFile()' in which you put:
JFileChooser fileChooser = new JFileChooser();
fileChooser.setFileFilter(new XMLFilter());