我正在使用名为 jfoenix 的库中的 JFXListView
和 JFXListCell
目的和功能与常规 ListView
相同。
该列表包含一些Label
、Button
和AnchorPane
。在列表的顶部和底部,我想添加不可选择的项目。项目不应在鼠标单击时可选
、不应聚焦
并且不应能够滚动
。
虽然我使用了 updateItem()
函数并将项目设置为禁用:
@FXML
JFXListView listView;
ObservableList<AnchorPane> list = FXCollections.observableArrayList();
private void initializeListView(){
AnchorPane headerBottomPane = new AnchorPane();
headerBottomPane.setId("headerBottomPane");
....//some property of AnchorPane
list.add(headerBottomPane); //Add header AnchorPane
while(true){
AnchorPane listContainer = new AnchorPane();
Label title = new Label();
Label subtitle = new Label();
Button button = new Button();
Button button2 = new Button();
//Some code here...
listContainer.getChildren().addAll(label, subtitle, button, button2);
list.add(listContainer);
//some code here...
}
list.add(headerBottomPane); //Add bottom AnchorPane
listView.setCellFactory(new CallBack<JFXListView, JFXListCell>(){
@Override
public JFXListCell call(JFXListView param){
return new JFXListCell<AnchorPane>(){
@Override
protected void updateItem(AnchorPane anchorPane, boolean empty){
super.updateItem(anchorPane, empty);
if(anchorPane != null){
if(anchorPane.getId.equals("headerBottomPane")){
setDisable(true);
}
setItem(anchorPane);
}else{
setItem(null);
}
}
};
}
});
}
我可以禁用列表的顶部和最后一项,不再能够使用 mouseClick
选择该项目。
但问题是,当我使用 Keyboard arrow up
和 arrow down
时,它是可聚焦的另一个奇怪的事情是当我使用 鼠标滚轮
滚动列表,一些项目也变得不可选择。
最佳答案
我会考虑只使用一个 VBox,并首先放置顶部不可选择的项目,然后是包含所有可选择项目的 ListView,然后是底部不可选择的项目...
关于JavaFX - 在 ListView 中创建不可选择的项目,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51434761/