我有一个TableView对象,双击表格的行后,我要显示URL的图像(该链接包含在我的类的其他对象中,作为String对象,例如“ http://。 。”)。但这不起作用,它显示了空白阶段。当我在文字上更改为代码String变量时,它将显示图像。不明白怎么了。
监听器用于表格行:
TableView<SimpleCharacter> centerPanel = new TableView<>();
Stage characterInfo = new Stage();
...
centerPanel.setRowFactory(tv -> {
TableRow<SimpleCharacter> row= new TableRow<>();
row.setOnMouseClicked(mouseEvent -> {
if(mouseEvent.getClickCount() == 2 && (! row.isEmpty())) {
SimpleCharacter selectedCharacter =
centerPanel.getSelectionModel().getSelectedItem();
characterInfo.setScene(new Scene(selectedCharacter.getInfo()));
characterInfo.show();
}
});
return row;
});
SimpleCharacter.getInfo()方法:
public class SimpleCharacter{
private Character character;
...
public VBox getInfo() {
VBox info = new VBox();
ImageView image = new ImageView(this.character.getImage());
info.getChildren().addAll(image, new Label(character.getName()));
return info;
}
...
}
字符类:
public class Character{
private String image;
public String getImage() {
return image;
}
}