Originariamente inviato da LucaTheDragon
Mi potreste fare un esempio completo di utilizzo di JFileChooser in versione salvataggio ma che permetta di salvare file solo con un'estensione definita da me!?
un'altra domanda: come faccio a far si ke il JFileChooser in apertura si apra sulla stessa directory del mio programma?
Grazie mille!
ciaooooooo!
ecco a te
Codice PHP:
File f = new File("");
JFileChooser fc = new JFileChooser();
fc.setFileFilter(new FileFilter() {
public String getDescription() {
return "lpx";
}
public boolean accept(File f) {
if (f.isDirectory()) {
return true;
}
if (f.getName().endsWith(".lpx")) {
return true;
}
return false;
}
});
fc.setDialogTitle("Salva con nome");
fc.setSelectedFile(new File("*.lpx"));
int v = fc.showSaveDialog(null);
if (v == JFileChooser.APPROVE_OPTION) {
try {
System.out.println(MTabbedP.mp.getComponents().toString());
Component[] co = MTabbedP.mp.getComponents();
for(int j=0;j<co.length;j++){
System.out.println(co[j].toString());
}
f = fc.getSelectedFile();
FileOutputStream file = new FileOutputStream(f);
ObjectOutputStream Output = new ObjectOutputStream(file);
Output.writeObject(PDpanel.model.getDataVector());
Output.close();