[英]JavaFX - TableView not populating with data
我正在为一个学校项目工作,但在让表格填充数据时遇到了麻烦。 在尝试将其实现到GUI之前,我创建了Tableview类作为测试。 它应该在一个表中添加2行,我可以看到这些行,因为我可以单击它们,但是没有数据显示。 这让我沮丧了几个小时,因此不胜感激。 提前致谢!
编辑我知道下面的代码不会显示此内容,但是我所有的类都在同一包中。
我刚刚在您的Part
类中添加了公共获取器和设置器,并且一切正常。 正如@Zephyr所提到的,您有一些奇怪的getter和setter,您可能应该检查一下体系结构。 所有的获取器和设置器必须是公共的,以便JavaFx可以将值注入到对象中。 这里是更正的Part
类:
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);
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.