JavaFX针对一个tableRow的多个CellValueFactorys?
我对JavaFX还是新手,不太了解工厂是如何工作的 我要做的是根据字符串值对tableColumn中的tableCell应用样式,并使单元格可编辑 现在,我的代码如下所示:JavaFX针对一个tableRow的多个CellValueFactorys?,javafx,tableview,javafx-8,Javafx,Tableview,Javafx 8,我对JavaFX还是新手,不太了解工厂是如何工作的 我要做的是根据字符串值对tableColumn中的tableCell应用样式,并使单元格可编辑 现在,我的代码如下所示: notesColumn.setCellFactory(column -> new TableCell<Computer, String>() { @Override protected void updateItem(String item, boolean empt
notesColumn.setCellFactory(column -> new TableCell<Computer, String>() {
@Override
protected void updateItem(String item, boolean empty) {
super.updateItem(item, empty);
if (item == null | empty)
{
setText(null);
setStyle("");
}
else
{
setText(item);
if (item.contains("Restoring @")) setTextFill(Color.CRIMSON);
else if (item.contains("Ready")) setTextFill(Color.FORESTGREEN);
else setTextFill(Color.BLACK);
}
}
});
以下方面应起作用:
notesColumn.setCellFactory(column -> new TextFieldTableCell<Computer, String>(new DefaultStringConverter()) {
@Override
public void updateItem(String item, boolean empty) {
super.updateItem(item, empty);
if (item == null | empty)
{
setStyle("");
}
else
{
if (item.contains("Restoring @")) setTextFill(Color.CRIMSON);
else if (item.contains("Ready")) setTextFill(Color.FORESTGREEN);
else setTextFill(Color.BLACK);
}
}
});
notesColumn.setCellFactory(列->新建TextFieldTableCell(新建DefaultStringConverter()){
@凌驾
public void updateItem(字符串项,布尔值为空){
super.updateItem(项,空);
如果(项==null |空)
{
设置样式(“”);
}
其他的
{
如果(项包含(“还原”))setTextFill(颜色为深红色);
else如果(item.contains(“Ready”))setTextFill(Color.FORESTGREEN);
else setTextFill(颜色:黑色);
}
}
});
以下各项应起作用:
notesColumn.setCellFactory(column -> new TextFieldTableCell<Computer, String>(new DefaultStringConverter()) {
@Override
public void updateItem(String item, boolean empty) {
super.updateItem(item, empty);
if (item == null | empty)
{
setStyle("");
}
else
{
if (item.contains("Restoring @")) setTextFill(Color.CRIMSON);
else if (item.contains("Ready")) setTextFill(Color.FORESTGREEN);
else setTextFill(Color.BLACK);
}
}
});
notesColumn.setCellFactory(列->新建TextFieldTableCell(新建DefaultStringConverter()){
@凌驾
public void updateItem(字符串项,布尔值为空){
super.updateItem(项,空);
如果(项==null |空)
{
设置样式(“”);
}
其他的
{
如果(项包含(“还原”))setTextFill(颜色为深红色);
else如果(item.contains(“Ready”))setTextFill(Color.FORESTGREEN);
else setTextFill(颜色:黑色);
}
}
});
只需将您的自定义单元格实现设置为TextFieldTableCell
的子类,而不是TableCell
的子类。您能说明一下我将如何实现吗?提前谢谢!不确定有什么需要澄清的?只需将自定义单元格实现设置为TextFieldTableCell
的子类,而不是TableCell
的子类。您能否澄清我将如何做到这一点?提前谢谢!不太确定有什么需要澄清的?谢谢。这就是我要找的!谢谢这就是我要找的!