Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import javafx.application.Application;
- import javafx.beans.property.SimpleStringProperty;
- import javafx.beans.property.StringProperty;
- import javafx.scene.Scene;
- import javafx.scene.control.TableColumn;
- import javafx.scene.control.TableView;
- import javafx.scene.control.cell.TextFieldTableCell;
- import javafx.stage.Stage;
- public class Main extends Application {
- @Override
- public void start(Stage primaryStage) throws Exception {
- TableColumn<Person, String> tcSurname = new TableColumn<>("Фамилия");
- tcSurname.setCellValueFactory(param -> param.getValue().surname);
- tcSurname.setCellFactory(TextFieldTableCell.forTableColumn());
- TableColumn<Person, String> tcName = new TableColumn<>("Имя");
- tcName.setCellValueFactory(param -> param.getValue().name);
- tcName.setCellFactory(TextFieldTableCell.forTableColumn());
- TableColumn<Person, String> tcPatronymic = new TableColumn<>("Отчество");
- tcPatronymic.setCellValueFactory(param -> param.getValue().patronymic);
- tcPatronymic.setCellFactory(TextFieldTableCell.forTableColumn());
- TableView<Person> tableView = new TableView<>();
- tableView.getColumns().addAll(tcSurname, tcName, tcPatronymic);
- tableView.setEditable(true);
- tableView.getItems().addAll(
- new Person("Иванов", "Иван", "Иванович"),
- new Person("Петров", "Петр", "Петрович"),
- new Person("Николаев", "Николай", "Николаевич")
- );
- primaryStage.setScene(new Scene(tableView, 300, 300));
- primaryStage.show();
- }
- private static class Person {
- StringProperty surname = new SimpleStringProperty(this, "surname");
- StringProperty name = new SimpleStringProperty(this, "name");
- StringProperty patronymic = new SimpleStringProperty(this, "patronymic");
- public Person(String surname, String name, String patronymic) {
- this.surname.set(surname);
- this.name.set(name);
- this.patronymic.set(patronymic);
- }
- }
- }
Add Comment
Please, Sign In to add comment