I have a weird problem in using TableView
my TableView Is showing blank line, what am I missing?
Controller.java
public class Controller {
@FXML private TableView<PersonalInfo> personalInfo = new TableView<>();
@FXML private TableColumn<PersonalInfo,String> tvId;
@FXML
public void initialize() {
tvId.setCellValueFactory(new PropertyValueFactory<>("Id"));
}
public void btnShow(ActionEvent actionEvent) {
List<PersonalInfo> participantList = new ArrayList<>();
participantList.add(new PersonalInfo("10") );
personalInfo.getItems().clear();
personalInfo.getItems().addAll(participantList);
}}
PersonalInfo:
public class PersonalInfo {
private String pId;
public PersonalInfo(String pId) {
this.pId = pId;
}
public PersonalInfo() {
}
public PersonalInfo setpId(String pId) {
this.pId = pId;
return this;
}
public String getpId() {
return pId;
}}
sample.fxml :
<children>
<TableView fx:id="personalInfo">
<columns>
<TableColumn fx:id="tvId" prefWidth="75.0" text="Id" />
</columns>
</TableView>
<Button mnemonicParsing="false" onAction="#btnShow" text="Show" GridPane.halignment="CENTER" GridPane.rowIndex="1" GridPane.valignment="CENTER" /></children>
above code only show a blank row what I can't see the content? enter image description here
Edit: Thanks, guys I found where I made a mistake as Slaw said the problem is I pass "Id" to PropertyValueFactory and in PersonalInfo.java file my getter and setter function is getpId and setpId so we have two option to fix it.
First:
we could change "Id" to "pId" and our setter and getter to getPId and setPId(because of java name convention)
Second :
we could change setter and getter function to getId and setId
then everything is fine and works perfectly.