【发布时间】:2016-10-04 11:00:21
【问题描述】:
我有一个 ListView,并添加了带有一些内容的 BorderPane 元素。
当我选择一个项目时,它会隐藏。
我该如何解决这个问题?
The white item is the selected item. Is hidden.
我在 listView 中没有任何 CSS
更新:
BorderPane 内容
public BorderPane getUserBox()
{
BorderPane borderPane = new BorderPane();
HBox mainPane = new HBox();
mainPane.prefWidthProperty().bind(borderPane.prefWidthProperty());
mainPane.minWidthProperty().bind(borderPane.minWidthProperty());
mainPane.maxWidthProperty().bind(borderPane.maxWidthProperty());
ImageView image = new ImageView(Images.CLOSE_ICON);
Label nick = new Label(" Name");
Label text = new Label(" Text ");
VBox vBox = new VBox();
vBox.getChildren().addAll(nick, text);
Label time = new Label(" 4.06.2016");
mainPane.getChildren().addAll(image, vBox, time);
borderPane.getStyleClass().add("userBox");
borderPane.setCenter(mainPane);
return borderPane;
}
添加边框
UserBox userBox = new UserBox();
ObservableList<BorderPane> items =FXCollections.observableArrayList (
userBox.getUserBox(), userBox.getUserBox(), userBox.getUserBox(), userBox.getUserBox());
listUsersBox.setItems(items);
我在borderPane中只有这个css
.userBox {
-fx-background-color: green;
}
【问题讨论】:
-
如果您没有实际发布您的 CSS 和 Java 代码,您希望我们如何帮助您找出您的 CSS/代码有什么问题?
-
为什么需要一些代码,只是一个Node(BorderPane),添加到一个ListView。此代码与问题无关。至少我是这么认为的。我用代码更新。
-
代码与问题无关?如果您的代码中没有错误,您认为导致问题的原因是什么?创建一个重现问题的minimal reproducible example 和edit 你的问题以包含它。
-
好的,我承认我错了,需要代码。但在这种情况下只是向 listView 添加一个节点,我添加的示例是一个新程序。只是一个ListView,getUserBox在一个空类中,并使用方法在ListView中添加元素。只有绿色的 CSS。
-
好的,很抱歉,感谢您花时间指导我。对不起,如果我让你生气了。我会修改其他部分代码,但其余代码只是一个装饰器类。