Guest User

Untitled

a guest
May 28th, 2018
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.11 KB | None | 0 0
  1. import javafx.application.Application;
  2. import javafx.beans.property.SimpleStringProperty;
  3. import javafx.beans.property.StringProperty;
  4. import javafx.scene.Scene;
  5. import javafx.scene.control.TableColumn;
  6. import javafx.scene.control.TableView;
  7. import javafx.scene.control.cell.TextFieldTableCell;
  8. import javafx.stage.Stage;
  9.  
  10. public class Main extends Application {
  11.  
  12. @Override
  13. public void start(Stage primaryStage) throws Exception {
  14. TableColumn<Person, String> tcSurname = new TableColumn<>("Фамилия");
  15. tcSurname.setCellValueFactory(param -> param.getValue().surname);
  16. tcSurname.setCellFactory(TextFieldTableCell.forTableColumn());
  17.  
  18. TableColumn<Person, String> tcName = new TableColumn<>("Имя");
  19. tcName.setCellValueFactory(param -> param.getValue().name);
  20. tcName.setCellFactory(TextFieldTableCell.forTableColumn());
  21.  
  22. TableColumn<Person, String> tcPatronymic = new TableColumn<>("Отчество");
  23. tcPatronymic.setCellValueFactory(param -> param.getValue().patronymic);
  24. tcPatronymic.setCellFactory(TextFieldTableCell.forTableColumn());
  25.  
  26. TableView<Person> tableView = new TableView<>();
  27. tableView.getColumns().addAll(tcSurname, tcName, tcPatronymic);
  28. tableView.setEditable(true);
  29.  
  30. tableView.getItems().addAll(
  31. new Person("Иванов", "Иван", "Иванович"),
  32. new Person("Петров", "Петр", "Петрович"),
  33. new Person("Николаев", "Николай", "Николаевич")
  34. );
  35.  
  36. primaryStage.setScene(new Scene(tableView, 300, 300));
  37. primaryStage.show();
  38. }
  39.  
  40. private static class Person {
  41.  
  42. StringProperty surname = new SimpleStringProperty(this, "surname");
  43. StringProperty name = new SimpleStringProperty(this, "name");
  44. StringProperty patronymic = new SimpleStringProperty(this, "patronymic");
  45.  
  46. public Person(String surname, String name, String patronymic) {
  47. this.surname.set(surname);
  48. this.name.set(name);
  49. this.patronymic.set(patronymic);
  50. }
  51. }
  52.  
  53. }
Add Comment
Please, Sign In to add comment