1

I need to draw an ImageView (Play button) before each track loaded from the database, but for some reason it doesn't load. No errors occur, but the button is simply not added to the line with the loaded track. I've already tried all possible methods. Maybe someone can tell me what's wrong

    @Override
    public void initialize(URL fxmlFileLocation, ResourceBundle resources) {
        try {
            column_track.setCellValueFactory(new PropertyValueFactory<>("title"));
            column_artist.setCellValueFactory(new PropertyValueFactory<>("artist"));
            column_genre.setCellValueFactory(new PropertyValueFactory<>("genre"));
            column_duration.setCellValueFactory(new PropertyValueFactory<>("duration"));
            column_play.setCellFactory(new Callback<TableColumn<Track, ImageView>, TableCell<Track, ImageView>>() {
                @Override
                public TableCell<Track, ImageView> call(TableColumn<Track, ImageView> param) {
                    return new TableCell<Track, ImageView>() {
                        private final ImageView imageView = new ImageView();

                        @Override
                        protected void updateItem(ImageView item, boolean empty) {
                            super.updateItem(item, empty);
                            if (empty || item == null) {
                                setGraphic(null);
                            } else {
                                imageView.setImage(new Image("images/icon-play-gray.png")); 
                                imageView.setFitWidth(50);
                                imageView.setFitHeight(50);
                                setGraphic(imageView);
                            }
                        }
                    };
                }
            });

            table_tracks.setItems(trackList);
            loadTracks();
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

}

7
  • 3
    When publishing code, please follow java naming conventions. Commented Feb 26 at 23:09
  • 3
    It is recommended to not use PropertyValueFactory -> that is not the root cause of your error though. Commented Feb 26 at 23:10
  • 3
    Ensure you understand and troubleshoot loading resources. For example, can you write a small app with no FXML and TableView that displays your play button image in an ImageView? Commented Feb 26 at 23:15
  • 3
    See Adding an image into a JavaFX TableView column -> perhaps this is a duplicate. Commented Feb 26 at 23:21
  • 3
    There is no cell value factory for your column_play, so the item in the cell will never be set or updated (the item should not be a node like an ImageView). Commented Feb 26 at 23:39

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.