Один щелчок → Выбрать ячейку (стандартное поведение) < /li>
Один щелчок по выбранной ячейке → «Режим стандартного поведения») < /li>
Щаспенение. /> < /ul>
Это таблица, которая показывает текущее и желаемое поведение: < /p>
< /th> < /th> < /th> < /th> < /th> < /th> < /th> < /th> < /th> < /th> < /th> < /th> < /th> < /th> < /th> < /th> < /th> < /th> < /th> < /th> < /th> < /th> < /th> < /th> < /th> < /th> /> < /tr>
< /thead>
однократный класс < /td>
selects < /td>
(Keep) select < /td>
< /tr>
/> входит в режим редактирования < /td>
(Keep) входит в режим редактирования < /td>
< /tr>
двойной щелк /> < /tbody>
< /table> < /div>
Это мой код: < /p>
Код: Выделить всё
public class NewMain1 extends Application {
public static class Person {
private final StringProperty firstName;
private final StringProperty lastName;
public Person(String firstName, String lastName) {
this.firstName = new SimpleStringProperty(firstName);
this.lastName = new SimpleStringProperty(lastName);
}
public StringProperty firstNameProperty() { return firstName; }
public StringProperty lastNameProperty() { return lastName; }
}
@Override
public void start(Stage primaryStage) {
TableView
tableView = new TableView();
tableView.setEditable(true);
TableColumn firstNameCol = new TableColumn("First Name");
firstNameCol.setCellValueFactory(cellData -> cellData.getValue().firstNameProperty());
firstNameCol.setCellFactory(TextFieldTableCell.forTableColumn());
firstNameCol.setOnEditStart(e -> System.out.println("First Name Edit Start"));
TableColumn lastNameCol = new TableColumn("Last Name");
lastNameCol.setCellValueFactory(cellData -> cellData.getValue().lastNameProperty());
lastNameCol.setCellFactory(TextFieldTableCell.forTableColumn());
lastNameCol.setOnEditStart(e -> System.out.println("Last Name Edit Start"));
tableView.getColumns().addAll(firstNameCol, lastNameCol);
ObservableList data = FXCollections.observableArrayList(
new Person("John", "Smith"),
new Person("Emily", "Johnson"),
new Person("Michael", "Williams"),
new Person("Sarah", "Brown")
);
tableView.setItems(data);
tableView.setRowFactory(tv -> {
TableRow row = new TableRow();
row.setOnMouseClicked(event -> {
if (event.getClickCount() == 2 && !row.isEmpty()) {
Person person = row.getItem();
System.out.println("DoubleClick on "
+ person.firstNameProperty().get() + " " + person.lastNameProperty().get());
event.consume();
}
});
return row;
});
VBox root = new VBox(tableView);
Scene scene = new Scene(root, 400, 300);
primaryStage.setScene(scene);
primaryStage.show();
}
public static void main(String[] args) {
launch(args);
}
}
Подробнее здесь: https://stackoverflow.com/questions/795 ... ping-singl