Here is an example that
- goes into edit mode as soon as you enter the focused cell
- creates a new line when you press enter in the last line (as an example). Alternatively, you can click the button to add a new line. If you want to use the tab on the last line to create a new line, you will have to change the code accordingly.
I would advise against using blank lines because they appear in your model.
InlineEditingWithDynamicRowAdding.java
import javafx.application.Application; import javafx.scene.control.TableView; import javafx.collections.ObservableList; import javafx.stage.Stage; import javafx.util.Callback; import javafx.scene.control.TableColumn; import javafx.scene.control.TableCell; import javafx.beans.property.SimpleDoubleProperty; import javafx.beans.property.DoubleProperty; import javafx.collections.FXCollections; import javafx.scene.input.KeyEvent; import javafx.event.EventHandler; import javafx.scene.control.SelectionMode; import javafx.scene.input.KeyCode; import javafx.scene.control.TablePosition; import javafx.scene.layout.FlowPane; import javafx.scene.control.Button; import javafx.scene.layout.BorderPane; import javafx.util.StringConverter; import javafx.scene.Scene; import javafx.scene.control.cell.TextFieldTableCell; public class InlineEditingWithDynamicRowAdding extends Application { private final ObservableList<Data> data = FXCollections.observableArrayList( new Data(1.,5.), new Data(2.,6.), new Data(3.,7.), new Data(4.,8.) ); private TableView<Data> table; @Override public void start(Stage stage) {
application.css
.text-field-table-cell .text-field { -fx-padding: 1; -fx-border-color:red; -fx-border-width:1; -fx-background-color:yellow; } .table-cell:focused { -fx-padding: 0; } .table-cell { -fx-alignment: CENTER-RIGHT; } .text-field { -fx-alignment: CENTER-RIGHT; } .table-row-cell:empty { -fx-background-color: white; } .table-row-cell:empty .table-cell { -fx-border-width: 0px; }

source share