简体   繁体   中英

JavaFX Not populating data in tableColumn

So I am trying to make a simple JavaFX program that displays a few tables of data. I have my model view controller, and from what I can tell everything looks clear. Running the application shows no problems except that no data shows up in the tables. The 4 tables are initialized, I can click on them so clearly its setting them up, just no data is being put inside them. Here is my code.

 package releaseData; import java.io.IOException; import java.util.Observable; import releaseData.model.ReleaseData; import releaseData.view.ShowReleaseDataController; import javafx.application.Application; import javafx.collections.FXCollections; import javafx.collections.ObservableList; import javafx.fxml.FXMLLoader; import javafx.scene.Scene; import javafx.scene.layout.AnchorPane; import javafx.stage.Stage; public class MainApp extends Application { private Stage primaryStage; //must match the the type of pane in .fxml file private AnchorPane rootLayout; //set up a list private ObservableList<ReleaseData> releaseData = FXCollections.observableArrayList(); //Constructor public MainApp() { releaseData.add(new ReleaseData("Borderlands", "2K", "11/24/2010", "4/5")); releaseData.add(new ReleaseData("Half-Life 2", "Valve", "9/9/2002", "5/5")); releaseData.add(new ReleaseData("Far Cry 3", "Activision", "12/1/2012", "5/5")); releaseData.add(new ReleaseData("Goat Simulator", "Coffe-Stain", "8/1/2014", "3/5")); } /** @return */ public ObservableList<ReleaseData> getReleaseData() { return releaseData; } @Override public void start(Stage primaryStage) { this.primaryStage = primaryStage; this.primaryStage.setTitle("Game Data"); initRootLayout(); } public void initRootLayout() { try { //Load fxml layout FXMLLoader loader = new FXMLLoader(); loader.setLocation(MainApp.class.getResource("view/releaseDataOverview.fxml")); rootLayout = (AnchorPane) loader.load(); //Give the controller access ShowReleaseDataController controller = loader.getController(); controller.setMainApp(this); //Show scene containing the root layout Scene scene = new Scene(rootLayout); primaryStage.setScene(scene); primaryStage.show(); }catch (IOException e) {e.printStackTrace(); } } public Stage getPrimaryStage() { return primaryStage; } public static void main(String[] args) { launch(args); } } 

 package releaseData.model; import javafx.beans.property.SimpleStringProperty; import javafx.beans.property.StringProperty; public class ReleaseData { private final StringProperty name; private final StringProperty publisher; private final StringProperty date; private final StringProperty rating; //Constructors public ReleaseData() { this(null, null, null, null); } public ReleaseData(String name, String publisher, String date, String rating){ this.name = new SimpleStringProperty(name); this.publisher = new SimpleStringProperty(publisher); this.date = new SimpleStringProperty(date); this.rating = new SimpleStringProperty(rating); } //Sets, gets, properties public String getName() { return name.get(); } public void setName(String name) {this.name.set(name); } public StringProperty nameProperty() { return name; } public String getPublisher() {return publisher.get(); } public void setPublisher(String publisher) {this.publisher.set(publisher); } public StringProperty publisherProperty() {return publisher; } public String getDate() { return date.get(); } public void setDate(String date) {this.date.set(date); } public StringProperty dateProperty() { return date; } public String getRating() { return rating.get(); } public void setRating(String rating) { this.rating.set(rating); } public StringProperty ratingProperty() {return rating; } } 

 package releaseData.view; import releaseData.MainApp; import releaseData.model.ReleaseData; import javafx.fxml.FXML; import javafx.scene.control.TableColumn; import javafx.scene.control.TableView; public class ShowReleaseDataController { @FXML private TableView<ReleaseData> releaseDataTable; @FXML private TableColumn<ReleaseData, String> nameColumn; @FXML private TableColumn<ReleaseData, String> publisherColumn; @FXML private TableColumn<ReleaseData, String> dateColumn; @FXML private TableColumn<ReleaseData, String> ratingColumn; private MainApp mainApp; public ShowReleaseDataController() {} @FXML private void initializer() { nameColumn.setCellValueFactory(cellData -> cellData.getValue().nameProperty()); publisherColumn.setCellValueFactory(cellData -> cellData.getValue().publisherProperty()); dateColumn.setCellValueFactory(cellData -> cellData.getValue().dateProperty()); ratingColumn.setCellValueFactory(cellData -> cellData.getValue().ratingProperty()); } public void setMainApp(MainApp mainApp) { this.mainApp=mainApp; releaseDataTable.setItems(mainApp.getReleaseData()); } } 

I've done about everything I can think of to find the issue. If someone could point me in the right direction I would be extremely grateful!

The initialisation method should be

public void initialize() {...}

not initializer()

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM