Reputation: 3
I'm working on a project for school and I'm having trouble getting my table to populate with data. I created the Tableview class as a test before I try to implement it into my GUI. It's supposed to add 2 rows to a table, and I can see the rows are there because I can click on them but there's no data showing. This has been frustrating me for hours so any help would be greatly appreciated. Thanks in advance!
Edit I know my code below doesn't show this but all of my classes are in the same package.
Upvotes: 0
Views: 132
Reputation: 549
I just added public getters and setters to your Part
class and everything works.
As @Zephyr fairly mentioned you have strange getters and setters, probably you should review your architecture. All getters and setters must be public so JavaFx can inject values to your object. Here is corrected Part
class:
public abstract class Part {
private int partID;
private String name;
private double price;
private int inStock;
private int min;
private int max;
static int partIDCount = 1;
private SimpleStringProperty tablePartID;
private SimpleStringProperty tablePartName;
private SimpleStringProperty tableInvLvl;
private SimpleStringProperty tablePrice;
void setName(String name){
this.name = name;
}
String getName(){
return this.name;
}
void setPrice(double price){
this.price = price;
}
double getPrice(){
return this.price;
}
void setInStock(int inStock){
this.inStock = inStock;
}
int getInStock(){
return this.inStock;
}
void setMin(int min){
this.min = min;
}
int getMin(){
return this.min;
}
void setMax(int max){
this.max = max;
}
int getMax(){
return this.max;
}
void setPartID(int partID){
this.partID = partID;
}
int getPartID(){
return this.partID;
}
void setTablePartID(){
this.tablePartID = new SimpleStringProperty(Integer.toString(this.partID));
}
SimpleStringProperty getTablePartID(){
return this.tablePartID;
}
void setTablePartName(){
this.tablePartName = new SimpleStringProperty(this.name);
}
SimpleStringProperty getTablePartName(){
return this.tablePartName;
}
void setTableInvLvl(){
this.tableInvLvl = new SimpleStringProperty(Integer.toString(inStock));
}
SimpleStringProperty getTableInvLvl(){
return this.tableInvLvl;
}
void setTablePrice(){
this.tablePrice = new SimpleStringProperty(Double.toString(price));
}
SimpleStringProperty getTablePrice(){
return this.tablePrice;
}
public SimpleStringProperty tablePartIDProperty() {
return tablePartID;
}
public void setTablePartID(String tablePartID) {
this.tablePartID.set(tablePartID);
}
public SimpleStringProperty tablePartNameProperty() {
return tablePartName;
}
public void setTablePartName(String tablePartName) {
this.tablePartName.set(tablePartName);
}
public SimpleStringProperty tableInvLvlProperty() {
return tableInvLvl;
}
public void setTableInvLvl(String tableInvLvl) {
this.tableInvLvl.set(tableInvLvl);
}
public SimpleStringProperty tablePriceProperty() {
return tablePrice;
}
public void setTablePrice(String tablePrice) {
this.tablePrice.set(tablePrice);
}
}
Upvotes: 0