Advertisement
Guest User

Untitled

a guest
Jun 24th, 2017
60
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.90 KB | None | 0 0
  1.         btnSeleccionar.addActionListener(new ActionListener() {
  2.             public void actionPerformed(ActionEvent e) {
  3.                 // Creamos el objeto JFileChooser
  4.                 JFileChooser fc = new JFileChooser();
  5.  
  6.                 // Indicamos lo que podemos seleccionar
  7.                 fc.setFileSelectionMode(JFileChooser.FILES_AND_DIRECTORIES);
  8.  
  9.                 // Creamos el filtro
  10.                 FileNameExtensionFilter filtro = new FileNameExtensionFilter("Images", "jpg", "png", "gif", "bmp");
  11.  
  12.                 // Le indicamos el filtro
  13.                 fc.setFileFilter(filtro);
  14.  
  15.                 // Abrimos la ventana, guardamos la opcion seleccionada por el usuario
  16.                 int seleccion = fc.showOpenDialog(contentPane);
  17.  
  18.                 // Si el usuario, pincha en aceptar
  19.                 if (seleccion == JFileChooser.APPROVE_OPTION) {
  20.                     // Seleccionamos el fichero
  21.                     File ficheros = fc.getSelectedFile();
  22.                    
  23.                     @SuppressWarnings("unused")
  24.                     Image image = new Image(ficheros.toString());
  25.                    
  26.                 }
  27.  
  28.             }
  29.         });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement