Goodevening everyone,JavaFX2.2並非所有的表列都顯示了PropertyValueFactory的數據?
今天我偶然發現了一個相當奇怪的問題,我不知道我做錯了什麼。它關於使用PropertyValueFactory綁定表列。我在FXML中創建了表視圖和表列,並使用Scene Builder設置了適當的fx:id。
現在的問題是,一些列顯示預期的數據等欄目都只是空的。我想補充的內容與下面的代碼表視圖,當用戶按下一個按鈕:
ObservableList<User> olUsers = DA_User.getUsers();
tbl_MC_Manage_Users.getItems().addAll(olUsers);
我肯定知道,在olUsers用戶對象包含所有需要的數據(以測試它的循環和系統。通過out.println)
我得到這樣一個結果:(<文本>代表列標題)
<disabled> <username> <title> <lastname> <firstname> <address> <zip> <city>
false (empty) Mr. (empty) (empty) address1 (empty) city1
false (empty) Miss (empty) (empty) address2 (empty) city2
所以出於某種原因colums用戶名,姓,名,拉鍊沒有顯示任何數據.. 。
控制器的某些部分:
//declaration (these are the fx:id's connected to my table colums)
@FXML private TableView<User> tbl_MC_Manage_Users;
@FXML private TableColumn<User,Boolean> tc_MC_Manage_Disabled;
@FXML private TableColumn<User,String> tc_MC_Manage_Username;
@FXML private TableColumn<User,String> tc_MC_Manage_Title;
@FXML private TableColumn<User,String> tc_MC_Manage_Lastname;
@FXML private TableColumn<User,String> tc_MC_Manage_Firstname;
@FXML private TableColumn<User,String> tc_MC_Manage_Address;
@FXML private TableColumn<User,String> tc_MC_Manage_ZipCode;
@FXML private TableColumn<User,String> tc_MC_Manage_City;
@Override
public void initialize(URL url, ResourceBundle rb) {
...
//setting the binding on the table columns at initialize();
tc_MC_Manage_Disabled.setCellValueFactory(new PropertyValueFactory<User, Boolean>("disabled"));
tc_MC_Manage_Username.setCellValueFactory(new PropertyValueFactory<User, String>("username"));
tc_MC_Manage_Title.setCellValueFactory(new PropertyValueFactory<User, String>("title"));
tc_MC_Manage_Firstname.setCellValueFactory(new PropertyValueFactory<User, String>("firstname"));
tc_MC_Manage_Lastname.setCellValueFactory(new PropertyValueFactory<User, String>("lastname"));
tc_MC_Manage_Address.setCellValueFactory(new PropertyValueFactory<User, String>("address"));
tc_MC_Manage_ZipCode.setCellValueFactory(new PropertyValueFactory<User, String>("zipcode"));
tc_MC_Manage_City.setCellValueFactory(new PropertyValueFactory<User, String>("city"));
...
}
以下是User類
private SimpleBooleanProperty disabled = new SimpleBooleanProperty();
private SimpleStringProperty username = new SimpleStringProperty("");
private SimpleStringProperty title = new SimpleStringProperty("");
private SimpleStringProperty lastname = new SimpleStringProperty("");
private SimpleStringProperty firstname = new SimpleStringProperty("");
//... (same for the others)
//getters
public boolean isDisabled() { return disabled.get(); }
public String getTitle() { return title.get(); }
public String getUsername() { return username.get(); }
public String getLastName() { return lastname.get(); }
public String getFirstName() { return firstname.get(); }
//... (same for the others)
//setters
public void setDisabled(boolean value) { disabled.set(value); }
public void setUsername(String value) { username.set(value); }
public void setTitle(String value) { title.set(value); }
public void setLastName(String value) { lastname.set(value); }
public void setFirstName(String value) { firstname.set(value); }
//... (same for the others)
對不起,我的代碼加載的某些部分,但我真的不明白爲什麼只有幾列得到他們的數據。我希望有人能指出我在正確的方向:)
提前感謝!
哈第二部分我怎麼會錯過了...感謝您的迅速和明確的答案謝爾蓋! – Perneel 2012-08-16 17:33:02
我遇到了setCellValueFactory(新的PropertyValueFactory(「第一個」))問題,其中第一個屬性。你的小費幫了我很多!我創建了公共SimpleBooleanProperty firstProperty()並且一切正常。謝謝謝爾蓋! – HowYaDoing 2017-09-25 18:56:27