gpt4 book ai didi

java - TableView不显示内容

转载 作者:行者123 更新时间:2023-12-02 05:14:38 27 4
gpt4 key购买 nike

我尝试使用 JavaFX 中的可观察 ArrayList 插入数据,但它没有显示我在列表中插入的数据。并且编译器不会显示错误。

public class EquipmentClass {

// declare instance variable of Equipment
private String brandEquipment;
private String modelEquipment;
private String typeEquipment;
private String colorEquipment;
private int lengthEquipment;
private int widthEquipment;
private int heightEquipment;
private int capacityEquipment;
private String user;
private String imageURL;

// constructor brandEquipment, modelEquipment, typeEquipment, colorEquipment, lengthEquipment, widthEquipment, HeightEquipment, capacityEquipment, user
public EquipmentClass(String brandEquipment, String modelEquipment,String typeEquipment, String colorEquipment, int lengthEquipment, int widthEquipment, int heightEquipment, int capacityEquipment,String imageURL) {
this.brandEquipment = brandEquipment;
this.modelEquipment = modelEquipment;
this.typeEquipment = typeEquipment;
this.colorEquipment = colorEquipment;
this.lengthEquipment = lengthEquipment;
this.widthEquipment = widthEquipment;
this.heightEquipment = heightEquipment;
this.capacityEquipment = capacityEquipment;

this.imageURL = imageURL;
}




// getter & setter methods
public String getBrandEquipment() {
return brandEquipment;
}

public void setBrandEquipment(String brandEquipment) {
this.brandEquipment = brandEquipment;
}

public String getModelEquipment() {
return modelEquipment;
}

public void setModelEquipment(String modelEquipment) {
this.modelEquipment = modelEquipment;
}

public String getTypeEquipment() {
return typeEquipment;
}

public void setTypeEquipment(String typeEquipment) {
this.typeEquipment = typeEquipment;
}

public String getColorEquipment(){
return colorEquipment;
}

public void setColorEquipment (String colorEquipment) {
this.colorEquipment = colorEquipment;
}

public int getLengthEquipment() {
return lengthEquipment;
}

public void setLengthEquipment (int lengthEquipment) {
this.lengthEquipment = lengthEquipment;
}

public int getWidthEquipment() {
return widthEquipment;
}

public void setWidthEquipment (int widthEquipment) {
this.widthEquipment = widthEquipment;
}

public int getHeightEquipment() {
return heightEquipment;
}

public void setHeightEquipment (int heightEquipment){
this.heightEquipment = heightEquipment;
}

public int getCapacityEquipment() {
return capacityEquipment;
}

public void setCapacityEquipment (int capacityEquipment) {
this.capacityEquipment = capacityEquipment;
}

public void setImageURL (String imageURL){
this.imageURL = imageURL;
}

public String getImageURL(){
return imageURL;
}


public String toString() {
return this.getClass().getSimpleName();
}
}

private ObservableList<EquipmentClass> getUserList() {

EquipmentClass user1 = new EquipmentClass("gh", "tim", "Sg", "Smith", 1,3,9,2," t");

EquipmentClass user2 = new EquipmentClass("smith", "sm","k", "S8h", 15,13,7,2," t");

EquipmentClass user3 = new EquipmentClass("smith", "sm", "Sh", "Shh", 8,5,78,8," t");


ObservableList<EquipmentClass> list = FXCollections.observableArrayList(user1, user2, user3);
return list;
}
TableView<EquipmentClass> table = new TableView<EquipmentClass>();

TableColumn<EquipmentClass,String>brand= new TableColumn<EquipmentClass,String>("Brand");

// Create column UserName (Data type of String).
TableColumn<EquipmentClass, String> model //
= new TableColumn<EquipmentClass, String>("Model");

TableColumn<EquipmentClass, String> type //
= new TableColumn<EquipmentClass, String>("Type");

TableColumn<EquipmentClass, String> color //
= new TableColumn<EquipmentClass, String>("Colour");

TableColumn<EquipmentClass, Integer> length //
= new TableColumn<EquipmentClass, Integer>("Length");

TableColumn<EquipmentClass, Integer> width //
= new TableColumn<EquipmentClass, Integer>("Width");

TableColumn<EquipmentClass, Integer> height //
= new TableColumn<EquipmentClass, Integer>("Height");

TableColumn<EquipmentClass, Integer> capacity //
= new TableColumn<EquipmentClass, Integer>("Capacity");

TableColumn<EquipmentClass, String> imageURL //
= new TableColumn<EquipmentClass, String>("Image");


brand.setCellValueFactory(new PropertyValueFactory<>("brand"));
model.setCellValueFactory(new PropertyValueFactory<>("model"));
type.setCellValueFactory(new PropertyValueFactory<>("type"));
color.setCellValueFactory(new PropertyValueFactory<>("color"));
length.setCellValueFactory(new PropertyValueFactory<>("length"));
width.setCellValueFactory(new PropertyValueFactory<>("width"));
height.setCellValueFactory(new PropertyValueFactory<>("height"));
capacity.setCellValueFactory(new PropertyValueFactory<>("cap"));
imageURL.setCellValueFactory(new PropertyValueFactory<>("img"));


// Display row data
ObservableList<EquipmentClass> list = getUserList();
table.setItems(list);
table.getColumns().addAll(brand,model,type,color,length,width,height,capacity,imageURL);

我期望输出应该有数据,但实际输出只显示表和表列的内容,不显示我放入可观察列表中的数据。

最佳答案

这部分

brand.setCellValueFactory(new PropertyValueFactory<>("brand"));
model.setCellValueFactory(new PropertyValueFactory<>("model"));
type.setCellValueFactory(new PropertyValueFactory<>("type"));
color.setCellValueFactory(new PropertyValueFactory<>("color"));
length.setCellValueFactory(new PropertyValueFactory<>("length"));
width.setCellValueFactory(new PropertyValueFactory<>("width"));
height.setCellValueFactory(new PropertyValueFactory<>("height"));
capacity.setCellValueFactory(new PropertyValueFactory<>("cap"));
imageURL.setCellValueFactory(new PropertyValueFactory<>("img"));

应该是这样的

brand.setCellValueFactory(new PropertyValueFactory<>("brandEquipment"));
model.setCellValueFactory(new PropertyValueFactory<>("modelEquipment"));
type.setCellValueFactory(new PropertyValueFactory<>("typeEquipment"));
color.setCellValueFactory(new PropertyValueFactory<>("colorEquipment"));
length.setCellValueFactory(new PropertyValueFactory<>("lengthEquipment"));
width.setCellValueFactory(new PropertyValueFactory<>("widthEquipment"));
height.setCellValueFactory(new PropertyValueFactory<>("heightEquipment"));
capacity.setCellValueFactory(new PropertyValueFactory<>("capacityEquipment"));
imageURL.setCellValueFactory(new PropertyValueFactory<>("imageURL"));

关于java - TableView不显示内容,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56305357/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com