Visualizzazione dei risultati da 1 a 4 su 4
  1. #1

    JFileChooser, esempio di salvataggio

    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!

  2. #2
    Utente di HTML.it L'avatar di Metflar
    Registrato dal
    Apr 2007
    Messaggi
    790

    Re: JFileChooser, esempio di salvataggio

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

                    }

                    
    fc.getSelectedFile();

                    
    FileOutputStream file = new FileOutputStream(f);

                    
    ObjectOutputStream Output = new ObjectOutputStream(file);

                    
    Output.writeObject(PDpanel.model.getDataVector());



                    
    Output.close(); 

  3. #3
    grazie ma a me serviva in java, nn in php

  4. #4
    Utente di HTML.it L'avatar di Metflar
    Registrato dal
    Apr 2007
    Messaggi
    790
    Originariamente inviato da LucaTheDragon
    grazie ma a me serviva in java, nn in php
    :| quello è java....ho usato i tag php per offrirti un indentatura e colorazione sintattica....
    codice:
    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 {
    
                    
                    f = fc.getSelectedFile();
    
                    FileOutputStream file = new FileOutputStream(f);
    
                    ObjectOutputStream Output = new ObjectOutputStream(file);
    
                    Output.writeObject(PDpanel.model.getDataVector());
    
    
    
                    Output.close();

Permessi di invio

  • Non puoi inserire discussioni
  • Non puoi inserire repliche
  • Non puoi inserire allegati
  • Non puoi modificare i tuoi messaggi
  •  
Powered by vBulletin® Version 4.2.1
Copyright © 2025 vBulletin Solutions, Inc. All rights reserved.