Search code examples
javafx-8

listcell disappears when updating image


When I update the status of the object in a list, a icon in the listCell object in a ListView should change. The progress and ok png works as it should, but when changing to any other png, the listCell object is removed.

Lets say the status changes from progress to critical, then the listcell is removed, but using the ok.png instead, then it won't be removed. So it seems to be something with the images.

critical pictue

ok picture

package MMaaSCollector.windows;

import java.io.IOException;

import MMaaSCollector.Log;
import MMaaSCollector.systems.Host;
import javafx.fxml.FXML;
import javafx.fxml.FXMLLoader;
import javafx.scene.control.Label;
import javafx.scene.image.Image;
import javafx.scene.image.ImageView;
import javafx.scene.layout.AnchorPane;

public class HostCellData {

@FXML private AnchorPane bg;
@FXML private Label displayName;
@FXML private Label type;
@FXML private ImageView status = new ImageView();

public HostCellData()
{
    FXMLLoader fxmlLoader = new FXMLLoader(getClass().getResource("/MMaaSCollector/windows/HostListCell.fxml"));
    fxmlLoader.setController(this);
    try
    {
        fxmlLoader.load();
    }
    catch (IOException e)
    {
        throw new RuntimeException(e);
    }
}

public void setInfo(Host host, double width) {
    displayName.setText(host.getDisplayName());
    type.setText(host.getType());
    bg.setPrefWidth(width-17.0-17.0);

    if (host.isStatusGathering()) {
        Image progress = new Image("/MMaaSCollector/images/progress.gif");
        status.setImage(progress);
        Log.debugInfo(host.getDisplayName() + " has progress indicator.", 96);
    } else if (host.isStatusFailed()) {
        Image failed = new Image("/MMaaSCollector/images/fail.png");
        status.setImage(failed);
        Log.debugInfo(host.getDisplayName() + " has failed indicator.", 96);
    } else if (host.isStatusOK()) {
        Image ok = new Image("/MMaaSCollector/images/ok.png");
        status.setImage(ok);
        Log.debugInfo(host.getDisplayName() + " has ok indicator.", 96);
    } else if (host.isStatusInfo()) {
        Image info = new Image("/MMaaSCollector/images/info.png");
        status.setImage(info);
        Log.debugInfo(host.getDisplayName() + " has info indicator.", 96);
    } else if (host.isStatusLow()) {
        Image low = new Image("/MMaaSCollector/images/low.png");
        status.setImage(low);
        Log.debugInfo(host.getDisplayName() + " has low indicator.", 96);
    } else if (host.isStatusWarning()) {
        Image warning = new Image("/MMaaSCollector/images/warning.png");
        status.setImage(warning);
        Log.debugInfo(host.getDisplayName() + " has warning indicator.", 96);
    } else if (host.isStatusCritical()) {
        Image critical = new Image("/MMaaSCollector/images/critical.png");
        status.setImage(critical);
        Log.debugInfo(host.getDisplayName() + " critical indicator.", 96);
    }
}

public AnchorPane getBg() {
    return bg;
}
}

Solution

  • Found the reason for why it's not working. Had to update the project in eclipse. Now when the images are in sync, it works as it should.