Icon is not compatible with String

1

I have this code and I want to use getLblFoto() to save a photo that the user chooses but every time I'm going to save it or every time I code it, it says getIcon is not compatible with String, which is the data type of the varible.

public void guardar()
{
  VentanaAgr_Contacto1 vn= new VentanaAgr_Contacto1();
  arreglo.add(new Controlador.Contacto(vn.getLblFoto().getIcon(),
                  vn.getTxt_Nombre().getText(),
                  vn.getTxt_Apellido().getText(),
                  vn.getTxt_Movil().getText(),
                  vn.getTxt_Casa().getText(),
                  vn.getTxt_Personal().getText(),
                  vn.getTxt_Trabajo().getText(),
                  vn.getTxtPanel_Direccion().getText()));
    }

The code where I load the image is this:

public void Cargar_Imagen() {
        File fichero;
        int resultado;
        VentanaImg_Contacto vi= new VentanaImg_Contacto();

        FileNameExtensionFilter filtro=
                new FileNameExtensionFilter("JPG y PNG", "jpg", "png");

        vi.getJchCargarFoto().setFileFilter(filtro);
        resultado= vi.getJchCargarFoto().showOpenDialog(null);

        if(JFileChooser.APPROVE_OPTION== resultado)
        {
            fichero= vi.getJchCargarFoto().getSelectedFile();
            try {
                ImageIcon icon= new ImageIcon(fichero.toString());
                Icon icono= new ImageIcon(icon.getImage().
                        getScaledInstance(VentanaAgr_Contacto1.lblFoto.getWidth(),
                                VentanaAgr_Contacto1.lblFoto.getHeight(), Image.SCALE_DEFAULT));
                VentanaAgr_Contacto1.lblFoto.setIcon(icono);
            } catch (Exception e) {
                JOptionPane.showMessageDialog(null, "Error al abrir la imagen "+e);
            }
        }else if(JFileChooser.CANCEL_SELECTION == null ? Integer.toString(resultado) == null : JFileChooser.CANCEL_SELECTION.equals(Integer.toString(resultado)))
            {
                vi.getJchCargarFoto().setVisible(false);
            }
    }

This presents the image in JLabel but I do not keep the image

    
asked by David Calderon 11.06.2016 в 00:52
source

1 answer

-2

Your method Controlador.Contacto() is ready to receive a String as the first parameter, you are sending a Icon :

vn.getLblFoto().getIcon()

change to:

vn.getLblFoto().getText()

to get the text of JLabel .

    
answered by 11.06.2016 в 01:50