JavaRush /Java Blog /Random-JA /TextField 要素と TableView 要素を操作する JavaFX。
Artemka58_1
レベル 21

TextField 要素と TableView 要素を操作する JavaFX。

Random-JA グループに公開済み
それを理解するのを手伝ってください。いくつかのクラスがあります。Employee クラスは、SimpleStringProperty タイプのデータを含めることができるオブジェクトです。Employees オブジェクトのリストを追加/変更するためのウィンドウ レイアウトを含む fxml ファイルがあります。AddEmployee クラスは、fxml ファイルのイベント ハンドラーです。選択したオブジェクトから TextField にテキストを追加すると、従業員が悪口を言い始めます。個別に見ると、データはオブジェクトから「抽出」されていますが、TextField に挿入することはできません。ハンドラー コード: @FXML private TextField tf_employee; @FXML private TextField tf_surname; @FXML private TextField tf_name; @FXML private TextField tf_patronymic; @FXML private TextField tf_post; Employees employees; public void setEmployees(Employees employees) { if (employees == null){ return; } this.employees = employees; tf_employee.setText(employees.getId_eml()); tf_employee.setText(employees.getId_eml().toString()); tf_surname.setText(employees.getSurname_empl()); tf_name.setText(employees.getName_empl().toString()); tf_patronymic.setText(employees.getPathronymic_empl()); tf_post.setText(employees.getPost_empl()); } オブジェクト コード: private SimpleStringProperty id_eml = new SimpleStringProperty(""); private SimpleStringProperty surname_empl = new SimpleStringProperty(""); private SimpleStringProperty name_empl = new SimpleStringProperty(""); private SimpleStringProperty pathronymic_empl = new SimpleStringProperty(""); private SimpleStringProperty post_empl = new SimpleStringProperty(""); public Employees(){} public Employees(String id_empl, String surname_empl, String name_empl, String pathronymic_empl, String post_empl) { this.id_eml = new SimpleStringProperty(id_empl); this.surname_empl = new SimpleStringProperty(surname_empl); this.name_empl = new SimpleStringProperty(name_empl); this.pathronymic_empl = new SimpleStringProperty(pathronymic_empl); this.post_empl = new SimpleStringProperty(post_empl); } public String getId_eml() { return id_eml.get(); } エラー: ウィンドウ自体Caused by: java.lang.NullPointerException at controllers.AddEmployee.setEmployees(AddEmployee.java:39) at controllers.EmployeesController.onButtonPressedAction(EmployeesController.java:89)を指します:tf_employee.setText(employees.getId_eml());TextField 要素と TableView 要素を操作する JavaFX。 - 1
コメント
TO VIEW ALL COMMENTS OR TO MAKE A COMMENT,
GO TO FULL VERSION