JavaFx TableView 文本換行


TableView 的TableColumn有文本換行的需求。

方法如下:

    @FXML
    private TableColumn nameCol;

    nameCol.setCellValueFactory(new PropertyValueFactory<>("name")); //姓名  初始化nameCol

   //設置nameCol中的文本可換行
    nameCol.setCellFactory(tc -> {

    TableCell<StaffModel,String> cell = new TableCell<>();
    Text text = new Text();
    cell.setGraphic(text);
    cell.setPrefHeight(Control.USE_COMPUTED_SIZE);
    text.wrappingWidthProperty().bind(nameCol.widthProperty());
    text.textProperty().bind(cell.itemProperty());
    return cell;
});

 

參考


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM