ฉันมีปัญหาง่าย ๆ ใน JavaFX ของฉันเพราะมันใช้งานไม่ได้ PropertyValueFactory
ไม่สามารถรับ ID
ของฉันจากคลาสได้: นี่คือคอนโทรลเลอร์ของฉัน:
public TableColumn ItemIDTableColumn;
ItemIDTableColumn.setCellValueFactory(new PropertyValueFactory<ReceiptItem, String>("mItemID"));
ItemIDTableColumn.setCellFactory(stringCellFactory);
ItemTableView.setItems(ReceiptItem);
Callback<TableColumn, TableCell> stringCellFactory =
new Callback<TableColumn, TableCell>() {
@Override
public TableCell call(TableColumn p) {
MyStringTableCell cell = new MyStringTableCell();
cell.addEventFilter(MouseEvent.MOUSE_CLICKED, new MyEventHandler());
return cell;
}
};
class MyStringTableCell extends TableCell<ReceiptItem, String> {
@Override
public void updateItem(String item, boolean empty) {
super.updateItem(item, empty);
setText(empty ? null : getString());
setGraphic(null);
}
private String getString() {
return getItem() == null ? "" : getItem().toString();
}
}
และนี่คือชั้นเรียนของฉัน:
package ModelData;
public class ReceiptItem {
private String mItemID;
public String getmItemID() {
return mItemID;
}
public void setmItemID(String mItemID) {
this.mItemID = mItemID;
}
}
อย่างที่เห็นที่นี่ ฉันกำลังใช้ getter และ setter มีใครรู้บ้างว่าปัญหาคืออะไร