问题
I want to make a custom TableColumn
that when in editable state it's cells will be auto complete TextField
s, here is what I tried:
public static <T,S> void setAutoCompleteTableColumn(TableColumn<T,S> column, List items){
column.setCellFactory(param -> {
return new TableCell<T, S>(){
final TextField textField = new TextField();
@Override
protected void updateItem(S item, boolean empty) {
super.updateItem(item, empty);
if(item == null){
setGraphic(null);
}else {
setGraphic(textField);
AutoCompletionBinding<T> binding = TextFields.bindAutoCompletion(textField,items);
binding.setOnAutoCompleted(event ->{
//handleCompleted.accept(event.getCompletion());
});
}
}
};
});
}
This code have produced (obviously) this:
But I want this form only when the TableView is in edit mode, So I did this instead:
public static <T,S> void setAutoCompleteTableColumn(TableColumn<T,S> column, List items){
column.setCellFactory(param -> {
return new TableCell<T, S>(){
final TextField textField = new TextField();
@Override
protected void updateItem(S item, boolean empty) {
super.updateItem(item, empty);
if(item == null){
setGraphic(null);
}else {
editableProperty().addListener((obs, oldValue, newValue)->{
if(newValue){
setGraphic(textField);
}else{
setText(item.toString());
}
});
AutoCompletionBinding<T> binding = TextFields.bindAutoCompletion(textField,items);
binding.setOnAutoCompleted(event ->{
//handleCompleted.accept(event.getCompletion());
});
}
}
};
});
}
As you can see I added a listener to editableProperty
, which resulted in nothing.
What I want is an editable TableColumn like in here, but with auto complete TextField
. Any idea how to accomplish this?
来源:https://stackoverflow.com/questions/41678347/javafx-custom-tablecolumn