简体   繁体   English

JavaFX:显示文本而不是布尔值(是/否)

[英]JavaFX: display text instead of boolean value (true/false)

I'm using tableview in JavaFX to display List<Contact> . 我在JavaFX使用tableview显示List<Contact>

For initialize function of the controller, the tableview columns are binded to List<Contact> as follow: 对于控制器的初始化功能,将tableview列绑定到List<Contact> ,如下所示:

sprintName.setCellValueFactory(new PropertyValueFactory<Contact, String>("name"));
importStatus.setCellValueFactory(new PropertyValueFactory<Contact, Boolean>("imported"));
enddate.setCellValueFactory(new PropertyValueFactory<Contact, String>("endDate"));

However, I want to display for column imported instead true/false the text imported/new 但是,我想显示imported的列,而不是显示true/false imported/new的文本imported/new

Is it possible in JavaFX or do I have to change the type of imported to String ? JavaFX是否可能,或者我必须将imported的类型更改为String

Use a cell factory (in addition to the cell value factory): 使用单元格工厂(除了单元格值工厂之外):

importStatus.setCellFactory(tc -> new TableCell<Contact, Boolean>() {
    @Override
    protected void updateItem(Boolean item, boolean empty) {
        super.updateItem(item, empty);
        setText(empty ? null :
            item.booleanValue() ? "imported" : "new");
    }
});

See the Cell class documentation for general information about the cell rendering mechanism. 有关单元渲染机制的一般信息,请参见Cell类文档

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM