Question

I have an Observer which my Window class. I have a Model class that extends Observable containing an ImagePanel class, and a Controller class. I do add to my Model instance the window.

My problem is : I do a print before model.notifyObservers(), it works, another print after this call, it works too. But the print inside the update() of my Observer method doesn't show up?

From my controller I call this setImage method:

public void setImage(File file)
    {
        try
    {
        image = ImageIO.read(file);
        fileName = file.getPath();
    } catch (IOException e)
    {
        e.printStackTrace();
    }
    width = image.getWidth();
    height = image.getHeight();
    imageType = image.getType();
    pixels = new int[width * height];
    image.getRGB(0, 0, width, height, pixels, 0, width);
    this.setLocation(1000, 500);
    System.out.println("ALRIGHT2");
    model.change();
    if (model.hasChanged())
    {
        System.out.println("ALRIGHT5");
        model.notifyObservers();
        System.out.println("ALRIGHT6");
    }
}

This is the update method of my Observer:

public void update(Observable o, Object arg) {
    System.out.println("ALRIGHT3");
    image_panel.repaint();
    scrollPaneImage.repaint();
}

And I did this in my Observer constructor: model.addObserver(this);

What's wrong? I assume that the image I chose thanks to a JFileChooser doesn't update because this method is not called...

Was it helpful?

Solution

Resolved ! Sorry for the inconvenience, my JScrollPane contains a JLabel which itself contains an ImageIcon and I forgot to update this ImageIcon...

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top