Ok...do un'occhiata intanto dti posto il codice...magari trovi qualche caxxata che ho combinato...perchè ho fatto in maniera un po' diversa...
codice:
import java.awt.*;
import javax.swing.*;
import javax.swing.filechooser.*;
import java.awt.BorderLayout;
import javax.swing.border.TitledBorder;
import javax.swing.border.EtchedBorder;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.File;
import java.io.FileOutputStream;
/**
*
Title: </p>
*
*
Description: </p>
*
*
Copyright: Copyright (c) 2007</p>
*
*
Company: </p>
*
* @author not attributable
* @version 1.0
*/
public class ExpFrame
extends JDialog {
//Flag for the Pack Frame
boolean packFrame = false;
//JavaGIS
JavaGIS gisdatabase = new JavaGIS();
//Parser
Parser parser = new Parser();
//ContentPane
JPanel contentPane;
//Layouts
BorderLayout borderLayout1 = new BorderLayout();
BorderLayout borderLayout2 = new BorderLayout();
//Panels
JPanel center = new JPanel();
JPanel west = new JPanel();
JPanel south = new JPanel();
JPanel east = new JPanel();
JPanel north = new JPanel();
//Title
TitledBorder titledBorder1 = new TitledBorder("Select the Location to Export");
//FileChooser
JFileChooser fileChooser = new JFileChooser();
public ExpFrame(JFrame owner) {
super(owner, true);
//Call to the jbInit
try {
jbInit();
}
catch (Exception exception) {
exception.printStackTrace();
}
}
/**
* Component initialization.
*
* @throws java.lang.Exception
*/
private void jbInit() throws Exception {
// Validate frames that have preset sizes
// Pack frames that have useful preferred size info, e.g. from their layout
if (packFrame) {
this.pack();
}
else {
this.validate();
}
//Frame Initialization
setSize(new Dimension(600, 450));
setResizable(false);
setTitle("Export File...");
contentPane = (JPanel) getContentPane();
contentPane.setLayout(borderLayout1);
//Position on the Screen
Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
Dimension frameSize = this.getSize();
if (frameSize.height > screenSize.height) {
frameSize.height = screenSize.height;
}
if (frameSize.width > screenSize.width) {
frameSize.width = screenSize.width;
}
this.setLocation( (screenSize.width - frameSize.width) / 2,
(screenSize.height - frameSize.height) / 2);
//Set Title to the center Panel
titledBorder1 = new TitledBorder(BorderFactory.createEtchedBorder(
EtchedBorder.RAISED, Color.white, new Color(134, 134, 134)),
"Select the Location to Export");
//Set Properties to the Center Panel
center.setLayout(borderLayout2);
center.setBorder(titledBorder1);
//Set Properties to the other Auxiliaries Panels
west.setBackground(Color.gray);
north.setBackground(Color.gray);
east.setBackground(Color.gray);
south.setBackground(Color.gray);
//Set Properties to the FileChooser
fileChooser.setMultiSelectionEnabled(true);
fileChooser.addActionListener(new ExpFrame_fileChooser_actionAdapter(this));
fileChooser.setApproveButtonText("Export");
fileChooser.setAcceptAllFileFilterUsed(false);
ExpFrame.JavaFilter filter = new JavaFilter();
fileChooser.setFileFilter(filter);
//Add all the Panel to the ContentPane
contentPane.add(center, java.awt.BorderLayout.CENTER);
contentPane.add(south, java.awt.BorderLayout.SOUTH);
contentPane.add(north, java.awt.BorderLayout.NORTH);
contentPane.add(west, java.awt.BorderLayout.WEST);
contentPane.add(east, java.awt.BorderLayout.EAST);
//Add FileChooser to the Center Panel
center.add(fileChooser, java.awt.BorderLayout.CENTER);
//Set Visible True
this.setVisible(true);
}
//Inner Class to Implement Files Filter
public class JavaFilter
extends FileFilter {
//Methods Overriding
//Description of the Files needed
public String getDescription() {
return "xml";
}
//Description of the Extension Accepted
public boolean accept(java.io.File file) {
return file.isDirectory() || file.getName().endsWith(".xml") ||
file.getName().endsWith(".xsd");
}
}
/**
* Events Management on the two Buttons: Import and Cancel
* @param e ActionEvent
*/
public void fileChooser_actionPerformed(ActionEvent e) {
//Event on the Button that Approve the Selection
if (e.getActionCommand().toString() == "ApproveSelection") {
try{
FileOutputStream f=new FileOutputStream(fileChooser.getSelectedFile().getAbsolutePath()+".xml");
}catch(Exception x){}
setVisible(false);
}
//Event on the Button that Cancel the Selection
if (e.getActionCommand().toString() == "CancelSelection") {
this.dispose();
}
}
}
//Class Adapter to Avoid the Overriding of all Methods
class ExpFrame_fileChooser_actionAdapter
implements ActionListener {
private ExpFrame adaptee;
ExpFrame_fileChooser_actionAdapter(ExpFrame adaptee) {
this.adaptee = adaptee;
}
//Function to Perform the Event
public void actionPerformed(ActionEvent e) {
adaptee.fileChooser_actionPerformed(e);
}
}