0

So basically in short terms i am doing an rpg type of game that has an inventory as a TableView and I want my items to be displayed there, but so far that doesn't seem to be working well. All the fx ids are set, yet whenever I run all I see is one column of empty boxes that can be selected.

This is the code for my 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);
   }
}

Code for the Items class:

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);
   }
}

This is how the output window looks like:

enter image description here

Aubin
  • 14,617
  • 9
  • 61
  • 84
MajorMajor
  • 1
  • 1
  • 1

1 Answers1

0

You have to add the accessors:

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; }
}
Aubin
  • 14,617
  • 9
  • 61
  • 84
  • 1
    It's rather unlikely that this is not done in the fxml... At least the screenshot shows 2 columns with similar text... – fabian Jan 29 '17 at 16:50
  • I haven't see the images, posts edited now. – Aubin Jan 29 '17 at 17:05
  • This wouldn't work. `getName()` should return a `String`; `nameProperty()` should return the `StringProperty`. See http://stackoverflow.com/questions/18971109/javafx-tableview-not-showing-data-in-all-columns, or just the [Oracle tutorial](http://www.oracle.com/pls/topic/lookup?ctx=javase80&id=JFXBD107). – James_D Jan 29 '17 at 17:18
  • Post edited James – Aubin Jan 29 '17 at 17:20
  • I am rather to sad say that this approach doesn't really solve this issue of mine. – MajorMajor Jan 29 '17 at 21:08