我想让我的列表单元格在悬停时显示“指针”/“按住”光标。 我已经设法定位整个 listView 并添加了背景颜色等,但它就像列表单元格不存在一样。我需要手动设置细胞工厂吗?
编辑: 我得到的答案是我不需要手动指定单元格,调用 .list-cell 应该足以添加样式。我的 CSS 应该可以正常工作,因为我设法更改其他元素的背景颜色,而不是 .list-cell。我也尝试过 fx-cursor
编辑2: 我现在已经在 scenebuilder Preview > Scene style sheets > add a style sheet 中进行了测试,并在该文档中放置了:
.list-cell{
-fx-cursor: pointer;
}
.test{
-fx-background-color: black;
}
当我用样本数据预览时仍然不行。
编辑3: Screenshot 光标未显示在屏幕截图中,但我可以向您展示我的 css 有效,只是不在列表单元格上。
到目前为止我已经尝试过:
CSS:
.list-cell{
-fx-background-color:black;
-fx-cursor: pointer;
}
#test .list-cell{
-fx-background-color:black;
-fx-cursor: pointer;
}
.test .list-cell{
-fx-background-color:black;
-fx-cursor: pointer;
}
Java:
teamListView.setCellFactory(new Callback<ListView<String>,
javafx.scene.control.ListCell<String>>()
{
@Override
public ListCell<String> call(ListView<String> teamListView)
{
return new ListCell();
}
});
代码:
我的 Controller :
public class MainPageController implements Initializable {
public static ObservableList<String> data =
FXCollections.observableArrayList();
@FXML
private Label label;
@FXML
private ListView<String> teamListView;
@Override
public void initialize(URL url, ResourceBundle rb) {
Team escala = new Team("Escala", "Conrad Adams", 4987000);
ArrayList<Team> teams = new ArrayList<Team>();
teams.add(escala);
data.add(teams.get(0).getName());
teamListView.setItems(data);
}
}
最佳答案
我得到了修复,但我没有解释:
改变
.list-cell{
-fx-cursor: hand;
}
到
.list{
}
.list-cell:filled:hover{
-fx-cursor: hand;
-fx-text-fill: dimgrey;
}
我的第一个 css 元素似乎被忽略了,其余的被激活了
关于java - 为什么我不能修改 ListView 中的列表单元格 css?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43553953/