JavaFx我在TableView中放置的项目没有显示出来

时间:2017-01-29 16:40:22

标签: java oop javafx tableview

所以基本上在短期内我正在做一个RPG类型的游戏,它有一个库存作为TableView,我希望我的项目显示在那里,但到目前为止,似乎并没有运作良好。所有fx id都已设置,但每当我运行时,我看到的是一列可以选择的空框。

这是我的TableViev的代码:

public class InventoryScreenController implements Initializable {

   @FXML private TableView<Items> table;
   @FXML private Button equipButton;
   @FXML private Button sortButton;
   @FXML private TableColumn<Items, String> name;
   @FXML private TableColumn<Items, Integer> value;

   public final ObservableList<Items> list =
      FXCollections.observableArrayList(new Items("huhhh",10));

   @Override
   public void initialize(URL url, ResourceBundle rb) {
      name.setCellValueFactory(new PropertyValueFactory<Items, String>("Name"));
      value.setCellValueFactory(new PropertyValueFactory<Items, Integer>("Value"));
      table.setItems(list);
   }
}

Items类的代码:

public class Items {

   private final SimpleStringProperty name;
   private final SimpleIntegerProperty value;

   public Items(String name, int value) {
      this.name = new SimpleStringProperty(name);
      this.value = new SimpleIntegerProperty(value);
   }
}

这是输出窗口的样子:

enter image description here

1 个答案:

答案 0 :(得分:0)

您必须添加访问者:

public class Items {

   private final SimpleStringProperty name;
   private final SimpleIntegerProperty value;

   public Items(String name, int value) {
      this.name = new SimpleStringProperty(name);
      this.value = new SimpleIntegerProperty(value);
   }

   public StringProperty nameProperty() { return name; }
   public StringProperty valueProperty() { return value; }
}
相关问题