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]
# 1
2) the filechooser comes (by default) with an "accept all" filter. you need to remove it and add your own filter that accepts directories and files that have a ".xml" extension.krwlaken
walken16a at 2007-7-13 23:02:31 > top of Java-index,Java Essentials,New To Java...
# 2
Cross-Post: http://forum.java.sun.com/thread.jspa?threadID=737215&tstart=0
BaltimoreJohna at 2007-7-13 23:02:31 > top of Java-index,Java Essentials,New To Java...
# 3

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());

Stonerose02a at 2007-7-13 23:02:31 > top of Java-index,Java Essentials,New To Java...
# 4
thanks a lot... nothing about the question 1)?
lastninjaa at 2007-7-13 23:02:31 > top of Java-index,Java Essentials,New To Java...