【发布时间】:2019-10-08 01:31:05
【问题描述】:
所以我有以下问题。 我有一个 JavaFX TableView,其中所有单元格都具有相同的样式,但只有一个。对于那个单元格,我想删除所有样式,但我猜 RowFactory 有一些优先级或其他什么。
我有一些类似的代码:
FXML
<TableView fx:id="tableView">
<columns>
<TableColumn fx:id="tcolNoStyle"/>
<TableColumn fx:id="tcolStyled"/>
</columns>
</TableView>
控制器
public class TableController {
@FXML
TableView<TableData> tableView;
@FXML
TableColumn<TableData, String> tcolNoStyle;
@FXML
TableColumn<TableData, String> tcolStyled;
@FXML
public void initialize(){
tableView.setRowFactory(row -> new RowFactory());
tcolNoStyle.setCellFactory(cell -> new CellFactoryForNoStyling());
}
}
表格背后的数据
public class TableData {
public final SimpleStringProperty noStyleTextProperty;
public final SimpleStringProperty styledTextProperty;
public TableData(){
noStyleTextProperty = new SimpleStringProperty();
styledTextProperty = new SimpleStringProperty();
}
}
行工厂
public class RowFactory extends TableRow<TableData> {
public RowFactory(){
itemProperty().addListener(((observable, oldValue, newValue) -> {
if (newValue != null){
setStyle("-fx-text-alignment: right");
}
}));
}
}
CellFactory 一个没有样式的 Cell
public class CellFactoryForNoStyling extends TableCell<TableData, String> {
public CellFactoryForNoStyling(){
super();
setStyle(null);
}
@Override
protected void updateItem(String item, boolean empty) {
super.updateItem(item, empty);
setStyle(null);
}
}
所以我想要的是,只有那一列应该没有样式
提前谢谢你!
【问题讨论】:
标签: javafx