javafx - 具有 CSS 滚动问题的 JavaFX tableview
问题描述
我目前面临 javafx 表的问题。我有一个显示主题列表的表格视图。每行的背景颜色取决于受试者是否能够注册。绿色背景的科目可以注册,粉红色背景的科目不能注册。滚动表格时会出现问题。
滚动后,行的背景颜色发生了变化,绿色背景的主题可能会变成粉红色,反之亦然。这可以完美地工作,而无需在表格中添加 css。
我用来设置行背景颜色的代码
tblAvailableSubjects.setRowFactory((TableView<Subject> param) -> {
TableRow<Subject> row = new TableRow<>();
row.emptyProperty().addListener((obs, wasEmpty, isEmpty) -> {
if(isEmpty) {
row.setContextMenu(null);
row.setStyle("-fx-border-color: transparent");
} else {
Subject subject = row.getItem();
if(subject.getSubjectEvaluation().equals(SubjectEvaluation.COMPLETED)) {
row.setStyle("-fx-background: #B2EBF2");
} else if(subject.getSubjectEvaluation().equals(SubjectEvaluation.FAILED)) {
row.setStyle("-fx-background: #FF0000");
row.setContextMenu(tblAvailableContext);
} else if(subject.getSubjectEvaluation().equals(SubjectEvaluation.OKAY)) {
row.setStyle("-fx-background: #8BC34A");
row.setContextMenu(tblAvailableContext);
} else if(subject.getSubjectEvaluation().equals(SubjectEvaluation.ENROLLWITHCOREQ)) {
row.setStyle("-fx-background: #FFEB3B");
row.setContextMenu(tblAvailableContext);
} else if(subject.getSubjectEvaluation().equals(SubjectEvaluation.CANTENROLL)) {
row.setStyle("-fx-background: #FFCDD2");
}
}
});
return row;
});
表格的 CSS
.table-view {
/* Constants used throughout the tableview. */
-fx-table-header-border-color: transparent;
-fx-table-cell-border-color: -fx-box-border;
/* Horizontal Lines*/
-fx-background-color: transparent;
}
.table-view .filler, .table-view .column-header
{
-fx-size: 40;
-fx-border-style: null;
-fx-border-color: rgb(200.0, 200.0, 200.0);
-fx-border-width: 0 0 1 0;
-fx-background-color: transparent;
}
.table-view .show-hide-columns-button
{
-fx-background-color: transparent;
}
.table-view .column-header .label,
.table-view .column-drag-header .label
{
-fx-alignment: CENTER_LEFT;
}
.table-view .column-header-background
{
-fx-background-color: transparent;
}
.table-row-cell {
-fx-cell-size: 30px;
}
.table-cell {
-fx-border-color: transparent;
-fx-border-width: 1;
}
编辑:主题的 SubjectEvaluation 值没有改变,它似乎在滚动时在行之间切换上下文菜单和背景颜色。
我希望有人可以帮助我解决这个问题。谢谢。
解决方案
推荐阅读
- apache-spark - 使用 pyspark 以交替的男性女性格式显示表格的性别
- python-3.x - 使用 KMeans 找到一组边界框质心?
- angular - PrimeNg 三态复选框不工作
- android - Mac m1 颤振项目未在 Android 设备或模拟器上运行
- python - 如何从不同长度的不同数据集中创建具有匹配值的列
- excel - VBA 在附件之前将 FileExist() 集成到循环中。添加链接
- angular - 在 Angular 中刷新子路由
- amazon-s3 - 跨账户解密的 KMS 密钥策略疑难解答
- javascript - 类型错误:firebaseApp.firestore 不是函数。在尝试在 Reactjs 项目中使用它时
- python - 获取在线客户端 python 套接字