X
X
xbs72018-12-12 14:35:28
Java
xbs7, 2018-12-12 14:35:28

How to insert an image as a link in a ListCell?

Greetings. Need help with listview, more specifically with listcell. You need to insert a link in new ImageView( imagery.getText() ) . Through the imagery variable in updateItem does not work. Throws an error URL must not be empty . If you create a string type variable and assign it a reference inside CustomListCell() or even where all variables are declared in general, then it works, but if you submit it from outside, it says that the variable is empty. Although in updateItem the system shows the value of the variable (the link itself). I don't quite understand what to do.

spoiler
public class CustomListCell extends ListCell<CustomThing> {

    private HBox content;
    private Text name;
    private Text price;
    private Text comments;
    private Text imagery;

    public CustomListCell() {
        super();
        name = new Text();
        price = new Text();
        comments = new Text();
        imagery = new Text();

        VBox vBox = new VBox(name, price,comments);

        content = new HBox(new ImageView(imagery.getText()),vBox);
        content.setSpacing(10);

}
    @Override
    public void updateItem(CustomThing item, boolean empty) {
        super.updateItem(item, empty);
        if (item != null && !empty) { // <== test for null item and empty parameter

            name.setText(item.getName());
            price.setText(item.getPrice());
            comments.setText(item.getComments());
            imagery.setText(item.getImagery());
            setGraphic(content);


        } else {
            setGraphic(null);
        }
    }}

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question