Foros del Web » Programación para mayores de 30 ;) » Java »

Elegir varios ficheros con JFileChooser

Estas en el tema de Elegir varios ficheros con JFileChooser en el foro de Java en Foros del Web. Hola tengo un problema cuando quiero que se puedan elegir varios ficheros con un JFileChooser, no sólo no me deja elegir varios ficheros, sino que ...
  #1 (permalink)  
Antiguo 15/01/2010, 06:36
 
Fecha de Ingreso: mayo-2009
Mensajes: 72
Antigüedad: 15 años
Puntos: 0
Elegir varios ficheros con JFileChooser

Hola tengo un problema cuando quiero que se puedan elegir varios ficheros con un JFileChooser, no sólo no me deja elegir varios ficheros, sino que si elijo 1 sólo, tampoco me lo coge:

Código:
private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {                                         
   JFileChooser fc = new JFileChooser();
   int returnVal = fc.showOpenDialog(this);
   if (returnVal == JFileChooser.APPROVE_OPTION) {
             
      fc.setFileSelectionMode(JFileChooser.FILES_ONLY);
      if (!fc.isMultiSelectionEnabled()) {
         fc.setMultiSelectionEnabled(true);
      }            
    
      File[] files = fc.getSelectedFiles();
      for (int i=0; i<files.length; i++) {
         jTextArea1.append(files[i].getName() + "\n");
      }
  }                      
}
En cambio usando fc.getSelectedFile() (osea cogiendolos de uno en uno) no me da ningún problema.

Muchas gracias!!!
  #2 (permalink)  
Antiguo 18/01/2010, 09:20
 
Fecha de Ingreso: enero-2009
Mensajes: 26
Antigüedad: 15 años, 3 meses
Puntos: 4
Respuesta: Elegir varios ficheros con JFileChooser

Deberías inicializar los parámetros de JFileChooser antes de mostrarle:
Código:
      fc.setFileSelectionMode(JFileChooser.FILES_ONLY);
      if (!fc.isMultiSelectionEnabled()) {
         fc.setMultiSelectionEnabled(true);
      }

      int returnVal = fc.showOpenDialog(this); 
Puede que el problema venga de ahí.
  #3 (permalink)  
Antiguo 22/01/2010, 04:03
 
Fecha de Ingreso: mayo-2009
Mensajes: 72
Antigüedad: 15 años
Puntos: 0
Respuesta: Elegir varios ficheros con JFileChooser

Muchas gracias!! ese era el problema!

Etiquetas: elegir, ficheros, jfilechooser
Atención: Estás leyendo un tema que no tiene actividad desde hace más de 6 MESES, te recomendamos abrir un Nuevo tema en lugar de responder al actual.
Respuesta

SíEste tema le ha gustado a 1 personas




La zona horaria es GMT -6. Ahora son las 07:42.