Placing an image into a JavaFX 2 table

前端 未结 2 1827
灰色年华
灰色年华 2021-01-06 16:12

I\'m trying to do something pretty simple. I want to place an icon in a column for a particular row in a table. If it\'s a folder, display a folder icon. If it\'s a file, di

2条回答
  •  猫巷女王i
    2021-01-06 17:07

    In case the provided answers did not work for you (like it didn't for me), this was the solution I found (Of course you still needs to create the tableView and add the columns to it):

    //Create your column that will hold the image    
    private final TreeTableColumn columnImage= new TreeTableColumn("Image");
    
    public void start() {
        //Set your cellValueFactory to a SimpleObjectProperty
        //Provided that your class has a method "getImage()" this will work beautifully!            
        columnImage.setCellValueFactory(c-> new SimpleObjectProperty(new ImageView(c.getValue().getValue().getImage())));
    }
    

提交回复
热议问题