This discussion is archived
1 Reply Latest reply: Sep 19, 2013 7:21 PM by James_D RSS

Display Image in TableCell

1010912 Newbie
Currently Being Moderated

Hi,

This might be a problem seen before but I'm really trying to do this by the Book !!

edit.setCellFactory(new Callback<TableColumn<Object, ImageView>, TableCell<Object, ImageView>>() {
                @Override
                public TableCell<Object, ImageView> call(TableColumn<Object, ImageView> param) {
                    TableCell<Object, ImageView> cell = new TableCell<Object, ImageView>() {
                        @Override
                        public void updateItem(ImageView item, boolean empty) {
                            if (item != null) {
                                HBox box = new HBox();
                                box.setSpacing(10);
                                VBox vbox = new VBox();
                                ImageView imageview = new ImageView();
                                imageview.setFitHeight(50);
                                imageview.setFitWidth(50);
                                imageview.setImage(new Image(getClass().getResource("edit.png").toExternalForm()));
                                box.getChildren().addAll(imageview, vbox);
                                //SETTING ALL THE GRAPHICS COMPONENT FOR CELL
                                setGraphic(box);
                            }
                        }
                    };
                    return cell;
                }
            });

 

when running the program, everything seems to be ok but actually nothing shows up in the tableCell !!

For some reason, it seems that the declaration of the Callback classes is wrong !!

All I'm trying is to add an edit icon to the a column that has no data in it !!

  • 1. Re: Display Image in TableCell
    James_D Guru
    Currently Being Moderated
    All I'm trying is to add an edit icon to the a column that has no data in it !!

    This might be your problem. If the column has no data, then the item will be null (if I understand you correctly). What is the cell value factory that is set on your column, and what are the items in the table?

Legend

  • Correct Answers - 10 points
  • Helpful Answers - 5 points