Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to open Save Dialog with filter ?

Status
Not open for further replies.

sergeiY

Programmer
Feb 13, 2003
132
AU
This is what I have and it works:

final JFileChooser fc = new JFileChooser();
int returnVal = fc.showSaveDialog(ApplicationFrame.this);

this is what I found in docs:
********************************************
public int showSaveDialog(java.lang.String extensionFilter)Opens a JFileChooser with the passed String as its File Filter. Will only display files ending with the passed String.

Parameters:
extensionFilter - String representing the extension of the files that will be displayed. For example, to select all Java source files, the String java will be passed. The . is not necessary.
Returns:
One of the following ints is returned:

JFileChooser.CANCEL_OPTION
JFileChooser.APPROVE_OPTION
JFileChooser.ERROR_OPTION if an error occurs or the chooser is dismissed.
********************************************

I've tried it and it doesn't work.... :(
 
actually now I have a problem with catching Save Dialog event...

here is my code:

final JFileChooser fc = new JFileChooser();
int returnVal = fc.showSaveDialog(ApplicationFrame.this);

try
{
System.out.println(returnVal + " return value ");
if (returnVal == javax.swing.JFileChooser.APPROVE_OPTION)
{
File file = fc.getSelectedFile();
FileOutputStream fos = new FileOutputStream (file.getName());
ObjectOutputStream out = new ObjectOutputStream(fos);
out.writeObject(myCanvas.getItems());
out.close();
myCanvas.repaint();
}
}
catch(Exception ex)
{
ex.printStackTrace();
System.out.println("IO EXCEPTION :" + ex.getMessage());
}

when I run it I get 0 ... it means it doesn't catch click on SAVE button... what am I doing wrong ???
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top