我有一個列綁定到一個可觀察列表不會顯示底層對象的字符串組件,但會顯示數字。我不明白這是可能的。這是我的代碼。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