I'm trying to add data to tableview repeatedly. But it doesn't append the data, it just overwrites it. How can i append the data to tableview without deleting old data from the table? Is there any way for me to tell to the program that the row it's trying to write on is not empty?
UserController Class
package entropy.myproject1;
import javafx.collections.FXCollections;
import javafx.collections.ObservableList;
import javafx.event.ActionEvent;
import javafx.fxml.FXML;
import javafx.fxml.FXMLLoader;
import javafx.fxml.Initializable;
import javafx.scene.control.TableColumn;
import javafx.scene.control.TableView;
import javafx.scene.control.cell.PropertyValueFactory;
import java.net.URL;
import java.util.ResourceBundle;
public class UsersController implements Initializable {
#FXML
private TableColumn<User, Integer> colID;
#FXML
private TableColumn<User, String> colPassword;
#FXML
private TableColumn<User, String> colUsername;
#FXML
private TableView<User> table;
RegisterController registerController = RegisterController.getInstance();
ObservableList<User> userList = FXCollections.observableArrayList(
new User(registerController.registeredUser.getId(),registerController.registeredUser.getUsername(),registerController.registeredUser.getPassword())
);
#Override
public void initialize(URL url, ResourceBundle resourceBundle) {
colID.setCellValueFactory(new PropertyValueFactory<User,Integer>("id"));
colUsername.setCellValueFactory(new PropertyValueFactory<User,String >("username"));
colPassword.setCellValueFactory(new PropertyValueFactory<User,String>("password"));
table.setItems(userList);
}
}
Register Controller Class
package entropy.myproject1;
import javafx.event.ActionEvent;
import javafx.fxml.FXML;
import javafx.fxml.FXMLLoader;
import javafx.scene.Node;
import javafx.scene.Parent;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.control.TextField;
import javafx.stage.Stage;
import java.io.IOException;
public class RegisterController {
private Stage stage;
private Scene scene;
private static final RegisterController instance = new RegisterController();
public static RegisterController getInstance(){
return instance;
}
#FXML
private Button buttonAdd;
#FXML
private TextField tfID;
#FXML
private TextField tfPassword;
#FXML
private TextField tfUsername;
public User registeredUser = User.getInstance();
#FXML
void addOnClick(ActionEvent event){
registeredUser.setId(Integer.parseInt(tfID.getText()));
registeredUser.setUsername(tfUsername.getText());
registeredUser.setPassword(tfPassword.getText());
System.out.println(registeredUser.toString());
}
#FXML
void showListOnClick(ActionEvent event) throws IOException {
Parent root = FXMLLoader.load(getClass().getResource("userspage.fxml"));
stage = (Stage)((Node)event.getSource()).getScene().getWindow();
scene = new Scene(root);
stage.setScene(scene);
stage.setTitle("User List");
stage.show();
}
}
User Class
package entropy.myproject1;
import javafx.beans.property.SimpleIntegerProperty;
import javafx.beans.property.SimpleStringProperty;
public class User {
private SimpleIntegerProperty id;
private SimpleStringProperty username;
private SimpleStringProperty password;
private static final User instance = new User();
public User(Integer id, String username, String password) {
this.id =new SimpleIntegerProperty(id);
this.username =new SimpleStringProperty(username);
this.password = new SimpleStringProperty(password);
}
public User() {
}
public int getId() {
return id.get();
}
public String getUsername() {
return username.get();
}
public String getPassword() {
return password.get();
}
public void setId(int id) {
this.id = new SimpleIntegerProperty(id);
}
public void setUsername(String username) {
this.username = new SimpleStringProperty(username);
}
public void setPassword(String password) {
this.password = new SimpleStringProperty(password);
}
public static User getInstance(){
return instance;
}
public String toString(){
return id+" "+username+" "+password;
}
}
Related
I'm to the end of this project that I working on learning Java/JavaFX it is an inventory management system, in the system, I should be able to create a product and assign parts from another ObservableList to that productID. The problem I am having is It will let me add the part in the GUI and it sends it to memory, but it is not sending it to the specific ID that I am trying to attach the part too. The code for the Product class and the controller are below:
package Model;
import javafx.collections.FXCollections;
import javafx.collections.ObservableList;
public class Product {
private static ObservableList<Part> part = FXCollections.observableArrayList();
private int productID;
private String name;
private double price;
private int inStock;
private int min;
private int max;
//Product constructor
public Product(int productID, String name, double price, int inStock, int min, int max) {
this.productID = productID;
this.name = name;
this.price = price;
this.inStock = inStock;
this.min = min;
this.max = max;
}
public static ObservableList<Part> getPart() {
return Product.part;
}
public void setPart(ObservableList<Part> part) {
Product.part = part;
}
}
package ViewController;
import Model.Inventory;
import Model.Part;
import Model.Product;
import javafx.collections.FXCollections;
import javafx.collections.ObservableList;
import javafx.fxml.FXMLLoader;
import javafx.fxml.Initializable;
import javafx.scene.Node;
import javafx.scene.Parent;
import javafx.scene.Scene;
import javafx.scene.control.*;
import javafx.scene.control.cell.PropertyValueFactory;
import javafx.scene.input.MouseEvent;
import javafx.stage.Stage;
import java.io.IOException;
import java.net.URL;
import java.util.Optional;
import java.util.ResourceBundle;
public class AddProduct implements Initializable {
public Button addProductSearchButton;
public Button addProductAddButton;
public Button addProductCancelButton;
public Button addProductSaveButton;
public Button addProductDeleteButton;
public TextField productIDTxtbox;
public TextField productNameTxtbox;
public TextField productInvTxtbox;
public TextField productMaxTxtField;
public TextField productPriceTxtbox;
public TextField productMinTxtbox;
public TextField productSearchTxtbox;
public TableView<Part> partSelectionTableview;
public TableColumn<Part, Integer> partSelectionIDColumn;
public TableColumn<Part, String> partSelectionNameColumn;
public TableColumn<Part, Integer> partSelectionInvColumn;
public TableColumn<Part, Double> partSelectionPriceColumn;
public TableView<Part> productPartsTableview;
public TableColumn<Part, Integer> productPartIDColumn;
public TableColumn<Part, String> productPartNameColumn;
public TableColumn<Part, Integer> productPartInvColumn;
public TableColumn<Part, Double> productPartPriceColumn;
private ObservableList<Part> availablePart = FXCollections.observableArrayList();
public void initialize(URL url, ResourceBundle rb){
partSelectionTableview.setItems(Inventory.getAllPart());
partSelectionIDColumn.setCellValueFactory(new PropertyValueFactory<>("partID"));
partSelectionNameColumn.setCellValueFactory(new PropertyValueFactory<>("partName"));
partSelectionInvColumn.setCellValueFactory((new PropertyValueFactory<>("partInStock")));
partSelectionPriceColumn.setCellValueFactory(new PropertyValueFactory<>("partPrice"));
productPartsTableview.setItems(availablePart);
productPartIDColumn.setCellValueFactory(new PropertyValueFactory<>("partID"));
productPartNameColumn.setCellValueFactory(new PropertyValueFactory<>("partName"));
productPartInvColumn.setCellValueFactory(new PropertyValueFactory<>("partInStock"));
productPartPriceColumn.setCellValueFactory(new PropertyValueFactory<>("partPrice")
public void addProductSaveButton(MouseEvent mouseEvent) throws IOException {
Product productadd = new Product(0,"",0.0,0,0,0);
if (productIDTxtbox.getText().isEmpty()){
productadd.setProductID(Inventory.getProductIDCount());
}
if (!productNameTxtbox.getText().isEmpty()){
productadd.setName(productNameTxtbox.getText());
}
if (!productPriceTxtbox.getText().isEmpty()){
productadd.setPrice(Double.parseDouble(productPriceTxtbox.getText()));
}
if (!productInvTxtbox.getText().isEmpty()){
productadd.setInStock(Integer.parseInt(productInvTxtbox.getText()));
}
if (!productMinTxtbox.getText().isEmpty()){
productadd.setMin(Integer.parseInt(productMinTxtbox.getText()));
}
if (!productMaxTxtField.getText().isEmpty()){
productadd.setMax(Integer.parseInt(productMaxTxtField.getText()));
}
if (!availablePart.isEmpty()) {
productadd.setPart(availablePart);
}
if(availablePart.isEmpty()){
Alert alert = new Alert(Alert.AlertType.INFORMATION);
alert.setHeaderText("All products must contain at least 1 Part!");
alert.showAndWait();
}
else {
Inventory.addProduct(productadd);
Parent addProductSave = FXMLLoader.load(getClass().getResource("MainScreen.fxml"));
Scene scene = new Scene(addProductSave);
Stage window = (Stage) ((Node) mouseEvent.getSource()).getScene().getWindow();
window.setScene(scene);
window.show();
}
}
Found the problem was trying to call a static method using a nonstatic method
we want to create a combobox within a table. Each combobox should have different options based on the row. In our example we have a table with different server ip addresses and a combobox with all the users on that server.
We have no idea how to populate the different options to the combobox inside the CellFactory and also we are not sure how to bind the comboxbox entry with the corresponding model.
We created an example, maybe someone has ideas:
CredentialModel
import javafx.beans.property.SimpleStringProperty;
import javafx.beans.property.StringProperty;
public class CredentialModel {
private StringProperty username = new SimpleStringProperty();
private StringProperty password = new SimpleStringProperty();
public CredentialModel(String username, String password) {
setUsername(username);
setPassword(password);
}
public String getUsername() {
return username.get();
}
public StringProperty usernameProperty() {
return username;
}
public void setUsername(String username) {
this.username.set(username);
}
public String getPassword() {
return password.get();
}
public StringProperty passwordProperty() {
return password;
}
public void setPassword(String password) {
this.password.set(password);
}
}
ServerModel
import javafx.beans.property.*;
import javafx.collections.FXCollections;
import javafx.collections.ObservableList;
public class ServerModel {
private IntegerProperty id = new SimpleIntegerProperty();
private StringProperty ip = new SimpleStringProperty();
private ObjectProperty<CredentialModel> credential = new SimpleObjectProperty<>();
private ObservableList<CredentialModel> allCredentials = FXCollections.observableArrayList();
public ObservableList<CredentialModel> getAllCredentials() {
return allCredentials;
}
public void setAllCredentials(ObservableList<CredentialModel> allCredentials) {
this.allCredentials = allCredentials;
}
public ServerModel(Integer id, String ip) {
setId(id);
setIp(ip);
}
public String getIp() {
return ip.get();
}
public StringProperty ipProperty() {
return ip;
}
public void setIp(String ip) {
this.ip.set(ip);
}
public CredentialModel getCredential() {
return credential.get();
}
public ObjectProperty<CredentialModel> credentialProperty() {
return credential;
}
public void setCredential(CredentialModel credential) {
this.credential.set(credential);
}
public int getId() {
return id.get();
}
public IntegerProperty idProperty() {
return id;
}
public void setId(int id) {
this.id.set(id);
}
}
And the main application TableApplication
import javafx.application.Application;
import javafx.collections.FXCollections;
import javafx.collections.ObservableList;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.control.TableCell;
import javafx.scene.control.TableColumn;
import javafx.scene.control.TableView;
import javafx.scene.layout.VBox;
import javafx.stage.Stage;
import javafx.util.Callback;
public class TableApplication extends Application {
public static void main(String[] args) {
Application.launch(args);
}
#Override
public void start(Stage primaryStage) throws Exception {
VBox box = new VBox();
TableView<ServerModel> tableView = new TableView<>();
TableColumn<ServerModel, String> ipColumn = new TableColumn<>("IP-Address");
TableColumn<ServerModel, CredentialModel> userColumn = new TableColumn<>("Username");
tableView.getColumns().addAll(ipColumn, userColumn);
ipColumn.setCellValueFactory(param -> param.getValue().ipProperty());
tableView.getItems().addAll(populateTable());
userColumn.setCellFactory(new Callback<TableColumn<ServerModel,CredentialModel>, TableCell<ServerModel,CredentialModel>>() {
#Override
public TableCell<ServerModel, CredentialModel> call(TableColumn<ServerModel, CredentialModel> param) {
return new UserComboBoxTableCell();
}
});
Button button = new Button("Start");
button.setOnAction(event -> System.out.println(tableView.getSelectionModel().getSelectedItem().getCredential().getUsername()));
box.getChildren().addAll(tableView, button);
Scene scene = new Scene(box,800, 600);
primaryStage.setScene(scene);
primaryStage.show();
}
private ObservableList<ServerModel> populateTable() {
ServerModel serverModel1 = new ServerModel(1, "192.168.0.1");
serverModel1.setAllCredentials(FXCollections.observableArrayList(new CredentialModel("user1", "pw1"), new CredentialModel("user2", "pw2")));
ServerModel serverModel2 = new ServerModel(2, "192.168.0.2");
serverModel2.setAllCredentials(FXCollections.observableArrayList(new CredentialModel("user3", "pw3")));
return FXCollections.observableArrayList(serverModel1, serverModel2);
}
And the TableCellClass UserComboBoxTableCell
import javafx.scene.control.ComboBox;
import javafx.scene.control.TableCell;
public class UserComboBoxTableCell extends TableCell<ServerModel, CredentialModel> {
public UserComboBoxTableCell() {
}
#Override
protected void updateItem(CredentialModel item, boolean empty) {
super.updateItem(item, empty);
if(empty == false) {
if(getTableRow() != null && getTableView() != null) {
int index = getTableRow().getIndex();
ServerModel serverModel = getTableView().getItems().get(index);
ComboBox<CredentialModel> box = new ComboBox<>(serverModel.getAllCredentials());
box.valueProperty().bindBidirectional(serverModel.credentialProperty());
setGraphic(box);
}
}
}
}
The idea of the methode loadCredentials is that for each row this methode should be called for "dummy"-loading the credentials for the server row.
The idea of the onAction method of the button is to display the selected username from the selected serverrow. In the moment we just print the ip address because the credential is always null (because it is not binded in the moment).
Thanks for your help.
Hauke
EDIT
I just added an observable list of credential models to the server and populated the list view differently. But still I am not sure how to set the options to the combobox within the CellFactory because I need to access the row and I am not sure about the binding.
EDIT2
Now it is working. I updated the examples above.
I would like to change the color of tableview based on some condition, i figured out how to do this, table is changing color as wanted but the only problem that im getting is that the value of table is not showing, i tried to system.out.println the value of the cell it is returning null, i wonder why ??
here is java code
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package gis_map;
import java.net.URL;
import java.util.ResourceBundle;
import javafx.beans.property.SimpleStringProperty;
import javafx.collections.ObservableList;
import javafx.fxml.FXML;
import javafx.fxml.Initializable;
import javafx.scene.control.Button;
import javafx.scene.control.TableColumn;
import javafx.scene.control.TableView;
import javafx.scene.layout.AnchorPane;
import javafx.collections.FXCollections;
import javafx.scene.control.TableCell;
import javafx.scene.control.cell.PropertyValueFactory;
import javafx.scene.paint.Color;
/**
* FXML Controller class
*
* #author HP
*/
public class CitizenScheduledController implements Initializable {
#FXML
private AnchorPane root;
#FXML
public TableView<citizen> scheduledCitizenTable;
#FXML
private Button approveBtn;
#FXML
private TableColumn<citizen, Integer> idColumn;
#FXML
private TableColumn<citizen, String> nameColumn;
#FXML
private TableColumn<citizen, String> addressColumn;
#FXML
private TableColumn<citizen, String> arrivalColumn;
#FXML
private TableColumn<citizen, String> departureColumn;
#FXML
private TableColumn<citizen, String> vehicleId;
#FXML
private TableColumn<citizen, Integer> waste;
#FXML
private TableColumn<citizen, String> remarks;
VehicleRoutingProblem vpr = new VehicleRoutingProblem();
public static ObservableList<citizen> List = FXCollections.observableArrayList(
// new citizen(1,"testing","testing","testing","testing")
);
public ObservableList<citizen> getList() {
return List;
}
public void setList(ObservableList<citizen> List) {
this.List = List;
}
#Override
public void initialize(URL url, ResourceBundle rb) {
//System.out.println("List contains"+List.size());
try{
vehicleId.setCellValueFactory(new PropertyValueFactory<citizen,String>("vehicleid"));
idColumn.setCellValueFactory(new PropertyValueFactory<citizen, Integer>("citizenId"));
nameColumn.setCellValueFactory(new PropertyValueFactory<citizen, String>("citizenName"));
addressColumn.setCellValueFactory(new PropertyValueFactory<citizen, String>("citizenAdress"));
arrivalColumn.setCellValueFactory(new PropertyValueFactory<citizen, String>("arrivalTime"));
departureColumn.setCellValueFactory(new PropertyValueFactory<citizen, String>("Departure"));
waste.setCellValueFactory(new PropertyValueFactory<citizen,Integer>("waste"));
remarks.setCellValueFactory(new PropertyValueFactory<citizen, String>("remarks"));
//actionColumn.setCellValueFactory(new PropertyValueFactory<>("citizenId"));;
vehicleId.setCellFactory(column -> {
return new TableCell<citizen, String>() {
#Override
protected void updateItem(String item, boolean empty) {
super.updateItem(item, empty);
if (item == null || empty) {
setText(getText());
setStyle("");
} else {
if (item.equals("vehicle1")) {
setText(getText());
setStyle("-fx-background-color: yellow");
System.out.println("getting the text for vehicle 1"+getText());
} else {
setText(getText());
setStyle("-fx-background-color: tomato");
}
}
}
};
});
scheduledCitizenTable.setItems(List);}catch(NullPointerException e){};
}
}
class citizen
package gis_map;
import javafx.beans.property.SimpleIntegerProperty;
import javafx.beans.property.SimpleStringProperty;
public class citizen {
private SimpleIntegerProperty citizenId;
private SimpleStringProperty citizenName;
private SimpleStringProperty citizenAdress;
private SimpleStringProperty arrivalTime;
private SimpleStringProperty Departure;
private SimpleStringProperty vehicleid;
private SimpleIntegerProperty waste;
private SimpleStringProperty remarks;
public citizen(String vehicleid,int citizenId, String citizenName, String citizenAdress, String arrivalTime, String Departure,int waste,String remarks) {
this.citizenId = new SimpleIntegerProperty (citizenId);
this.waste = new SimpleIntegerProperty (waste);
this.vehicleid = new SimpleStringProperty (vehicleid);
this.citizenName = new SimpleStringProperty(citizenName);
this.citizenAdress =new SimpleStringProperty (citizenAdress);
this.arrivalTime = new SimpleStringProperty(arrivalTime);
this.Departure = new SimpleStringProperty (Departure);
this.remarks = new SimpleStringProperty (remarks);
}
public int getCitizenId() {
return citizenId.get();
}
public String getVehicleid() {
return vehicleid.get();
}
public String getCitizenName() {
return citizenName.get();
}
public String getCitizenAdress() {
return citizenAdress.get();
}
public String getArrivalTime() {
return arrivalTime.get();
}
public String getDeparture() {
return Departure.get();
}
public Integer getWaste() {
return waste.get();
}
public String getRemarks() {
return remarks.get();
}
}
below is the output
click here to see results
I'm trying to put a SimpleStringProperty on a TableView this is the class im using:
package com.launch.history;
import java.net.URL;
import java.util.ResourceBundle;
import com.launch.WebController;
import javafx.collections.FXCollections;
import javafx.collections.ObservableList;
import javafx.event.EventHandler;
import javafx.fxml.FXML;
import javafx.fxml.Initializable;
import javafx.scene.control.TableColumn;
import javafx.scene.control.TableView;
import javafx.scene.control.cell.PropertyValueFactory;
import javafx.scene.input.MouseEvent;
public class HistoryController implements Initializable {
#FXML
private TableView<HistoryClient> tableView;
#FXML
private TableColumn<HistoryClient, String> tableColumn;
#Override
public void initialize(URL location, ResourceBundle resources) {
setTableView();
}
public void setColumns() {
tableColumn.setCellValueFactory(new PropertyValueFactory<HistoryClient, String>("history"));
}
public void setTableView() {
tableView.setItems(getHistory());
setColumns();
tableView.setOnMouseClicked(new EventHandler<MouseEvent>() {
#SuppressWarnings("static-access")
#Override
public void handle(MouseEvent event) {
if(tableView.getSelectionModel().getSelectedIndex() >= 0) {
HistoryClient link = tableView.getSelectionModel().getSelectedItem();
WebController.engine.load(link.getHistory());
}
}
});
}
public ObservableList<HistoryClient> getHistory() {
ObservableList<HistoryClient> data = FXCollections.observableArrayList();
data.addAll(new HistoryClient());
return data;
}
}
And this is the the stuff about history:
public static String getHistory() {
return history.get();
}
public static void setHistory(String history) {
HistoryClient.history.set(history);
}
private static SimpleStringProperty history = new SimpleStringProperty();
But i only get 1 line on my TableView(The last link)
And this is how i set the value of history:
public static void readHistory() {
if(Files.HISTORY_FILE.exists()) {
try(BufferedReader in = new BufferedReader(new FileReader(Files.HISTORY_FILE))) {
String line;
while( (line = in.readLine()) != null) {
history.set(line);
}
} catch (IOException e) {
e.printStackTrace();
}
}
}
That works fine i printed out history and it was the same as in the file so i really don't see the problem because last time when i used TableView i kinda did the same thing.
And yes i did set the fx:id in scene builder.
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()