我有一个列绑定到一个可观察列表不会显示底层对象的字符串组件,但会显示数字。我不明白这是可能的。这是我的代码。JAVAFX列不填充字符串
产品类别
public class Product {
private String name;
private double quantity;
private double cost;
public Product(String name, double quantity, double cost)
{
this.name = name;
this.quantity = quantity;
this.cost = cost;
}
}
主控制器
public class MainMenuController implements Initializable {
@FXML
private TableView<Product> tblReceipt;
@FXML
private TableColumn<Product, String> colName;
@FXML
private TableColumn<Product, String> colQuantity;
@FXML
private TableColumn<Product, String> colPrice;
private double total;
private final ObservableList<Product> data = FXCollections.observableArrayList(new Product("Steak", 1, 2.00), new Product("Eggs", 3, 5.00));
@Override
public void initialize(URL url, ResourceBundle rb) {
tblReceipt.setEditable(false);
colName.setCellValueFactory(new PropertyValueFactory<>("name"));
colQuantity.setCellValueFactory(new PropertyValueFactory<>("quantity"));
colPrice.setCellValueFactory(new PropertyValueFactory<>("cost"));
tblReceipt.setItems(data);
}
FXML
<TableView fx:id="tblReceipt" layoutX="7.0" layoutY="34.0" prefHeight="375.0" prefWidth="227.0">
<columns>
<TableColumn fx:id="colName" prefWidth="75.0" text="Item" />
<TableColumn fx:id="colQuantity" prefWidth="75.0" text="Quantity" />
<TableColumn fx:id="colPrice" prefWidth="75.0" text="Price" />
</columns>
我从现场建设者的错误是没有注射领域COLNAME这是问题。但是,显然在那里。
请发布错误,与堆栈跟踪,这将有助于他人帮助你。 – Les
并且还发布**。FXML **文件,以便我们可以帮助(: – Anas
step before ya there。Thanks yall。 – FamousFrik