【发布时间】:2016-07-04 19:30:43
【问题描述】:
我正在为我的大学项目开发 GUI, 我必须连续显示一系列由颜色定义的元素。 因为它们可以在运行时更改,所以我使用了 ListView。 元素不能超过四个,它们应该占据一定数量的空间,但是当我将节点放在列表的单元格内时,单元格会在节点周围显示一个边框(在这种情况下是一个矩形)使 ListView 超出他的首选尺寸并显示两个滚动条,我不想看到这两个滚动条,因为 List 不应该是可滚动的,而且它真的很小,所以条形几乎覆盖了所有滚动条。
这是我为细胞工厂编写的代码:
private void initializeBalcony(SimpleListProperty<String> balconyProperty, ListView<String> balconyView) {
balconyView.setBorder(null);
balconyView.setItems(balconyProperty);
balconyView.setCellFactory(row -> new ListCell<String>() {
@Override
protected void updateItem(String item, boolean empty) {
super.updateItem(item, empty);
if (item == null || empty)
Platform.runLater(() -> this.setGraphic(null));
else {
this.setMaxSize(27.5, 38);
Rectangle councillor = new Rectangle();
councillor.setWidth(20);
councillor.setHeight(35);
councillor.setFill(Paint.valueOf(item));
Platform.runLater(() -> this.setGraphic(councillor));
}
}
});
}
加上 ListView 的 FXML 定义:
<ListView fx:id="coastBalcony" fixedCellSize="38.0" layoutX="80.0" orientation="HORIZONTAL" prefHeight="40.0" prefWidth="120.0" />
Graphical display of the problem
我不知道我做错了什么,也许我应该只使用和HBox,但我曾经遇到过ListChangeListeners的问题。
【问题讨论】:
标签: java listview user-interface javafx