Forum Stats

  • 3,875,092 Users
  • 2,266,805 Discussions
  • 7,912,078 Comments

Discussions

Populate a TableView with items in an Observable list

Hi, my TableView doesn't display any data. Here is my code :

MODEL :

public class Tech {

     private transient SimpleStringProperty quad;

   

     public Tech () {

          quad = new SimpleStringProperty("DHOE");

     }

   

     public SimpleStringProperty getQuad() {

          return quad;

     }

  

      public void setQuad(String quad) {

          this.quad.set(quad);

     }

}

CONTROLLER :

public class TechController{

     @FXML

     private TableView<Tech> techTableView;


     @FXML

     private TableColumn<Tech, String> codeColumn;

     private transient ObservableList<Tech> techList;

     private void initialize(){

          mockData();

          codeColumn.setCellValueFactory(cellData -> cellData.getValue().getQuad());

     }

     private void mockData(){

          techList = FXCollections.observableArrayList();

          Tech tech0 = new Tech();

          techList.add(tech0);

     }

}

VIEW :

The table and the column fx:id are declared and linked to the TableView and Column in the fxml file with Scenebuilder. The controller is also linked with the view using Scenebuilder.

PROBLEM :

My Table displays "no data to display" when I launch my app. How do I put my list item from techlist in the TableView Cell? Thanks for your help!

Best Answer

Answers

This discussion has been closed.