
Imagenes en .jar
Publicado por Antonio (1 intervención) el 02/06/2018 12:28:38
Hola, tengo este código que en NetBeans funciona perfectamente, copia la imagen en la carpeta Images/usaurios
y la muestra en en JLabel llamado lblImagen.
El problema esta en cuando genero el ejecutable(.jar), en el .jar ya no se muestran ni se guardan las imágenes porque la carpeta src no existe. Alguien sabe que ruta hay que poner para guardar la rimagen en el .jar
y la muestra en en JLabel llamado lblImagen.
El problema esta en cuando genero el ejecutable(.jar), en el .jar ya no se muestran ni se guardan las imágenes porque la carpeta src no existe. Alguien sabe que ruta hay que poner para guardar la rimagen en el .jar
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
String ruta = "";
String pathOrigen;
String pathDestino;
JFileChooser file = new JFileChooser();
int estado=file.showOpenDialog(this);
if(estado==JFileChooser.APPROVE_OPTION);
{
imagen = file.getSelectedFile().getName();
//-----------------------------------------------
pathOrigen = file.getSelectedFile().getAbsolutePath();
pathDestino = "src/Images/usuarios/" + imagen;
File origen = new File(pathOrigen);
File destino = new File(pathDestino);
try {
InputStream in = new FileInputStream(origen);
OutputStream out = new FileOutputStream(destino);
byte[] buf = new byte[1024];
int len;
while ((len = in.read(buf)) > 0) {
out.write(buf, 0, len);
}
in.close();
out.close();
} catch (IOException ex) {
Logger.getLogger(FrmProducto.class.getName()).log(Level.SEVERE, null, ex);
}
//-----------------------------------------------
ruta = "src/Images/usuarios/" + imagen;
ImageIcon fot = new ImageIcon(ruta);
Icon icono = new ImageIcon(fot.getImage().getScaledInstance(lblImagen.getWidth(), lblImagen.getHeight(), Image.SCALE_DEFAULT));
lblImagen.setIcon(icono);
lblImagen.repaint();
Valora esta pregunta


0