我有一个带有自定义 ListCellFactory 的 ListView。在我的 CustomListCell 实现中,我使用 setGraphic 将列表项图形设置为 GridPane,但我不能不让 GridPane 填充 ListView 的整个宽度。以下是我的代码的简短版本:
class MyListCell extends ListCell<MyObject>
{
private final GridPane _myComponent;
public MyListCell()
{
...
setContentDisplay(ContentDisplay.GRAPHIC_ONLY); // does not help
//this.setPrefWidth(0); // does not help
myComponent.prefWidthProperty().bind(this.widthProperty()); // does not help
}
...
@Override
protected void updateItem(MyObject item, boolean empty)
{
...
setGraphic(_myComponent);
...
}
}
即使使用另一个帖子的 prefWidth 边界,我的 GridPane 也不会增长!无论我使用哪种布局约束组合,它看起来都如下所示:
GridPane 应扩展到 ListCell 的整个宽度(我想在右下角添加一个删除按钮)。我快疯了,求救!