JavaFX why TableView don't load data - javafx

I just don't get what I'm doing wrong. Everything seems OK, but data just don't wont to load in table.
This is controller class of stage:
package application.controllers;
import application.meetings.MeetingData;
import javafx.collections.FXCollections;
import javafx.collections.ObservableList;
import javafx.event.ActionEvent;
import javafx.fxml.FXML;
import javafx.scene.control.*;
import javafx.scene.control.cell.PropertyValueFactory;
import java.net.URL;
import java.util.ResourceBundle;
public class EditMeetingPopUpController {
#FXML // ResourceBundle that was given to the FXMLLoader
private ResourceBundle resources;
#FXML // URL location of the FXML file that was given to the FXMLLoader
private URL location;
#FXML // fx:id="dateAndTimeInformation"
private DatePicker dateAndTimeInformation; // Value injected by FXMLLoader
#FXML // fx:id="hoursInformation"
private ComboBox<String> hoursInformation; // Value injected by FXMLLoader
#FXML // fx:id="minutesInformation"
private ComboBox<String> minutesInformation; // Value injected by FXMLLoader
#FXML // fx:id="placeInformation"
private TextField placeInformation; // Value injected by FXMLLoader
#FXML // fx:id="categoryInformation"
private ComboBox<String> categoryInformation; // Value injected by FXMLLoader
#FXML // fx:id="contactsInformation"
private ComboBox<String> contactsInformation; // Value injected by FXMLLoader
#FXML // fx:id="allSelectedContactsTextArea"
private TextArea allSelectedContactsTextArea; // Value injected by FXMLLoader
#FXML // fx:id="commentInformation"
private TextArea commentInformation; // Value injected by FXMLLoader
// Table variables
#FXML // fx:id="meetingTable"
private TableView<MeetingData> meetingTable; // Value injected by FXMLLoader
#FXML // fx:id="dateAntTimeColumn"
private TableColumn<MeetingData, String> dateAntTimeColumn; // Value injected by FXMLLoader
#FXML // fx:id="placeColumn"
private TableColumn<MeetingData, String> placeColumn; // Value injected by FXMLLoader
#FXML // fx:id="categoryColumn"
private TableColumn<MeetingData, String> categoryColumn; // Value injected by FXMLLoader
#FXML // fx:id="contactsColumn"
private TableColumn<MeetingData, String> contactsColumn; // Value injected by FXMLLoader
#FXML // fx:id="commentsColumn"
private TableColumn<MeetingData, String> commentsColumn; // Value injected by FXMLLoader
#FXML // Add more contactsColumn to contactsColumn list
void addContactToAllContactsTextArea(ActionEvent event) {
}
#FXML
void editMeeting(ActionEvent event) {
}
#FXML
void loadInformationForMeeting(ActionEvent event) {
ObservableList<MeetingData> data = getMeetingData();
this.meetingTable = new TableView<>();
this.meetingTable.setItems(data);
this.placeColumn.setCellValueFactory(new PropertyValueFactory<MeetingData, String>("date"));
this.placeColumn.setCellValueFactory(new PropertyValueFactory<MeetingData, String>("place"));
this.categoryColumn.setCellValueFactory(new PropertyValueFactory<MeetingData, String>("category"));
this.contactsColumn.setCellValueFactory(new PropertyValueFactory<MeetingData, String>("contacts"));
this.commentsColumn.setCellValueFactory(new PropertyValueFactory<MeetingData, String>("comments"));
this.meetingTable.getColumns().add(this.dateAntTimeColumn);
this.meetingTable.getColumns().add(this.placeColumn);
this.meetingTable.getColumns().add(this.categoryColumn);
this.meetingTable.getColumns().add(this.contactsColumn);
this.meetingTable.getColumns().add(this.commentsColumn);
// // TODO: 01-Feb-17 delete this after finish
// for (MeetingData meetingData : data) {
// System.out.println(meetingData.getDate());
// System.out.println(meetingData.getPlace());
// System.out.println(meetingData.getCategory());
// System.out.println(meetingData.getContacts());
// System.out.println(meetingData.getComments());
// System.out.println("----- END -----");
// System.out.println();
// }
}
// get all meetings
public ObservableList<MeetingData> getMeetingData() {
ObservableList<MeetingData> data = FXCollections.observableArrayList();
data.add(new MeetingData("sdzgzrdbf", "sgzsfbs", "EDbfb", "sbdbf", "zbdd"));
data.add(new MeetingData("sEDGdb", "sgzsfbs", "EDbfb", "sbdbf", "zbdd"));
data.add(new MeetingData("sdzgsbfgzrdbf", "sgzsfbs", "EDbfb", "sbdbf", "zbdd"));
data.add(new MeetingData("zsrbd", "sgzsfbs", "EDbfb", "sbdbf", "zbdd"));
data.add(new MeetingData("rbdbdb", "sgzsfbs", "EDbfb", "sbdbf", "zbdd"));
data.add(new MeetingData("rsbdbd", "sgzsfbs", "EDbfb", "sbdbf", "zbdd"));
return data;
}
#FXML // This method is called by the FXMLLoader when initialization is complete
void initialize() {
assert dateAndTimeInformation != null : "fx:id=\"dateAndTimeInformation\" was not injected: check your FXML file 'EditMeetingPopUp.fxml'.";
assert hoursInformation != null : "fx:id=\"hoursInformation\" was not injected: check your FXML file 'EditMeetingPopUp.fxml'.";
assert minutesInformation != null : "fx:id=\"minutesInformation\" was not injected: check your FXML file 'EditMeetingPopUp.fxml'.";
assert placeInformation != null : "fx:id=\"placeInformation\" was not injected: check your FXML file 'EditMeetingPopUp.fxml'.";
assert categoryInformation != null : "fx:id=\"categoryInformation\" was not injected: check your FXML file 'EditMeetingPopUp.fxml'.";
assert contactsInformation != null : "fx:id=\"contactsInformation\" was not injected: check your FXML file 'EditMeetingPopUp.fxml'.";
assert allSelectedContactsTextArea != null : "fx:id=\"allSelectedContactsTextArea\" was not injected: check your FXML file 'EditMeetingPopUp.fxml'.";
assert commentInformation != null : "fx:id=\"commentInformation\" was not injected: check your FXML file 'EditMeetingPopUp.fxml'.";
assert meetingTable != null : "fx:id=\"meetingTable\" was not injected: check your FXML file 'EditMeetingPopUp.fxml'.";
assert dateAntTimeColumn != null : "fx:id=\"dateAntTimeColumn\" was not injected: check your FXML file 'EditMeetingPopUp.fxml'.";
assert placeColumn != null : "fx:id=\"placeColumn\" was not injected: check your FXML file 'EditMeetingPopUp.fxml'.";
assert categoryColumn != null : "fx:id=\"categoryColumn\" was not injected: check your FXML file 'EditMeetingPopUp.fxml'.";
assert contactsColumn != null : "fx:id=\"contactsColumn\" was not injected: check your FXML file 'EditMeetingPopUp.fxml'.";
assert commentsColumn != null : "fx:id=\"commentsColumn\" was not injected: check your FXML file 'EditMeetingPopUp.fxml'.";
}
}
This is data class:
package application.meetings;
public class MeetingData {
// Fields
private String date;
private String place;
private String category;
private String contacts;
private String comments;
// Constructors
public MeetingData(String date, String place, String category, String contacts, String comments) {
this.date = date;
this.place = place;
this.category = category;
this.contacts = contacts;
this.comments = comments;
}
// Setters
public void setDate(String date) {
this.date = date;
}
public void setPlace(String place) {
this.place = place;
}
public void setCategory(String category) {
this.category = category;
}
public void setContacts(String contacts) {
this.contacts = contacts;
}
public void setComments(String comments) {
this.comments = comments;
}
// Getters
public String getDate() {
return date;
}
public String getPlace() {
return place;
}
public String getCategory() {
return category;
}
public String getContacts() {
return contacts;
}
public String getComments() {
return comments;
}
}
And finally FXML file:
<?xml version="1.0" encoding="UTF-8"?>
<?import javafx.geometry.*?>
<?import javafx.scene.control.*?>
<?import javafx.scene.control.cell.PropertyValueFactory?>
<?import javafx.scene.layout.*?>
<?import javafx.scene.text.Font?>
<BorderPane maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" prefHeight="450.0" prefWidth="1000.0" xmlns="http://javafx.com/javafx/8.0.60" xmlns:fx="http://javafx.com/fxml/1" fx:controller="application.controllers.EditMeetingPopUpController">
<bottom>
<HBox alignment="CENTER_RIGHT" BorderPane.alignment="CENTER">
<children>
<Button mnemonicParsing="false" onAction="#loadInformationForMeeting" text="Зареди информация">
<HBox.margin>
<Insets right="10.0" />
</HBox.margin>
</Button>
<Button defaultButton="true" mnemonicParsing="false" onAction="#editMeeting" prefWidth="80.0" text="Редактирай">
<HBox.margin>
<Insets />
</HBox.margin></Button>
</children>
<BorderPane.margin>
<Insets />
</BorderPane.margin>
</HBox>
</bottom>
<center>
<VBox alignment="CENTER">
<children>
<HBox alignment="CENTER_LEFT">
<children>
<Label prefWidth="70.0" text="Дата" />
<DatePicker fx:id="dateAndTimeInformation" prefWidth="220.0" promptText="Дата" showWeekNumbers="true">
<HBox.margin>
<Insets left="20.0" />
</HBox.margin>
<tooltip>
<Tooltip text="Полето е задължително" />
</tooltip>
</DatePicker>
</children>
<VBox.margin>
<Insets bottom="10.0" />
</VBox.margin>
</HBox>
<HBox alignment="CENTER_LEFT">
<children>
<Label prefWidth="70.0" text="Час" />
<ComboBox fx:id="hoursInformation" prefWidth="70.0">
<HBox.margin>
<Insets left="20.0" right="5.0" />
</HBox.margin>
<tooltip>
<Tooltip text="Полето е задължително" />
</tooltip>
</ComboBox>
<Label text="часa">
<HBox.margin>
<Insets right="20.0" />
</HBox.margin>
</Label>
<ComboBox fx:id="minutesInformation" prefWidth="70.0">
<HBox.margin>
<Insets right="5.0" />
</HBox.margin>
<tooltip>
<Tooltip text="Полето е задължително" />
</tooltip>
</ComboBox>
<Label text="мин.">
<HBox.margin>
<Insets />
</HBox.margin>
</Label>
</children>
<VBox.margin>
<Insets bottom="10.0" />
</VBox.margin>
</HBox>
<HBox alignment="CENTER_LEFT" layoutX="10.0" layoutY="218.0">
<children>
<Label prefWidth="70.0" text="Място" />
<TextField fx:id="placeInformation" prefWidth="220.0" promptText="Място на срещата">
<HBox.margin>
<Insets left="20.0" />
</HBox.margin>
</TextField>
</children>
<VBox.margin>
<Insets bottom="10.0" />
</VBox.margin>
</HBox>
<HBox alignment="CENTER_LEFT" layoutX="10.0" layoutY="253.0">
<children>
<Label prefWidth="70.0" text="Категория" />
<ComboBox fx:id="categoryInformation" prefWidth="220.0" promptText="Изберете категория">
<HBox.margin>
<Insets left="20.0" />
</HBox.margin>
</ComboBox>
</children>
<VBox.margin>
<Insets bottom="10.0" />
</VBox.margin>
</HBox>
<HBox alignment="CENTER_LEFT" layoutX="10.0" layoutY="240.0">
<children>
<Label prefWidth="70.0" text="Участници" />
<ComboBox fx:id="contactsInformation" onAction="#addContactToAllContactsTextArea" prefWidth="220.0" promptText="Изберете участници">
<HBox.margin>
<Insets left="20.0" />
</HBox.margin>
<tooltip>
<Tooltip text="Полето е задължително" />
</tooltip>
</ComboBox>
</children>
<VBox.margin>
<Insets bottom="10.0" />
</VBox.margin>
</HBox>
<HBox>
<children>
<Pane prefHeight="100.0" prefWidth="70.0" />
<TextArea fx:id="allSelectedContactsTextArea" editable="false" prefHeight="100.0" prefWidth="220.0" promptText="Участници в срещата">
<HBox.margin>
<Insets left="20.0" />
</HBox.margin>
</TextArea>
</children>
<VBox.margin>
<Insets bottom="10.0" />
</VBox.margin>
</HBox>
<HBox alignment="CENTER_LEFT" layoutX="10.0" layoutY="293.0">
<children>
<Label alignment="TOP_LEFT" prefHeight="100.0" prefWidth="70.0" text="Коментар" />
<TextArea fx:id="commentInformation" prefHeight="100.0" prefWidth="220.0" promptText="Въведете коментар">
<HBox.margin>
<Insets bottom="10.0" left="20.0" />
</HBox.margin>
<tooltip>
<Tooltip text="Полето е задължително" />
</tooltip>
</TextArea>
</children>
<VBox.margin>
<Insets />
</VBox.margin>
</HBox>
</children>
</VBox>
</center>
<left>
<VBox BorderPane.alignment="CENTER">
<BorderPane.margin>
<Insets />
</BorderPane.margin>
</VBox>
</left>
<padding>
<Insets bottom="20.0" left="20.0" right="20.0" top="20.0" />
</padding>
<top>
<Label alignment="CENTER" prefWidth="600.0" text="Моля изберете среща за редактиране">
<font>
<Font name="System Bold" size="14.0" />
</font>
<BorderPane.margin>
<Insets bottom="10.0" left="360.0" />
</BorderPane.margin>
</Label>
</top>
<right>
<TableView fx:id="meetingTable" editable="true" prefWidth="600.0" BorderPane.alignment="CENTER">
<columns>
<TableColumn fx:id="dateAntTimeColumn" prefWidth="75.0" text="Дата и час" >
<cellValueFactory>
<PropertyValueFactory property="date" />
</cellValueFactory>
</TableColumn>
<TableColumn fx:id="placeColumn" prefWidth="75.0" text="Място" >
<cellValueFactory>
<PropertyValueFactory property="place" />
</cellValueFactory>
</TableColumn>
<TableColumn fx:id="categoryColumn" prefWidth="75.0" text="Категория" >
<cellValueFactory>
<PropertyValueFactory property="category" />
</cellValueFactory>
</TableColumn>
<TableColumn fx:id="contactsColumn" prefWidth="75.0" text="Участници" >
<cellValueFactory>
<PropertyValueFactory property="contacts" />
</cellValueFactory>
</TableColumn>
<TableColumn fx:id="commentsColumn" prefWidth="114.0" text="Коментар" >
<cellValueFactory>
<PropertyValueFactory property="comments" />
</cellValueFactory>
</TableColumn>
</columns>
<BorderPane.margin>
<Insets bottom="10.0" />
</BorderPane.margin>
<columnResizePolicy>
<TableView fx:constant="CONSTRAINED_RESIZE_POLICY" />
</columnResizePolicy>
</TableView>
</right>
</BorderPane>
I would be very grateful if you can help me and explain from where is mistake.

First, your loadInformationforMeeting() method creates a new TableView, adds data to it, reconfigures the table columns (with the same configuration they already have...) and adds the table columns to the new table.
However, since the new table is not ever placed in the UI, you never see the data. There is no need to create a new table.
Secondly, if you use the existing table (the one defined by the FXML file), it already has the columns attached, and those columns already have cell value factories. So you should not add the columns to the table again, and do not need to repeat the configuration of the columns.
All you need is
#FXML
void loadInformationForMeeting(ActionEvent event) {
ObservableList<MeetingData> data = getMeetingData();
this.meetingTable.setItems(data);
}

Related

Values not getting populated in TableView [duplicate]

This question already has answers here:
Javafx PropertyValueFactory not populating Tableview
(2 answers)
Javafx tableview not showing data in all columns
(3 answers)
Closed 1 year ago.
I am using the following code to generate a TableView:
#FXML
private TableView<Customer> customerTable;
#FXML
private TableColumn<Customer, String> customerIDColumn;
#FXML
private TableColumn<Customer, String> customerNameColumn;
#FXML
private TableColumn<Customer, String> customerPhoneColumn;
#FXML
private TableColumn<Customer, String> customerAddressColumn;
#FXML
private TableColumn<Customer, String> customerPostalCodeColumn;
#FXML
private TableColumn<Customer, String> customerDivisionColumn;
#FXML
private TableColumn<Customer, String> customerCountryColumn;
ObservableList<Customer> customerOL = FXCollections.observableArrayList();
PropertyValueFactory<Customer, String> custCustomerIDFactory = new PropertyValueFactory<>("customerID");
PropertyValueFactory<Customer, String> custNameFactory = new PropertyValueFactory<>("customerName");
PropertyValueFactory<Customer, String> custPhoneFactory = new PropertyValueFactory<>("phone"); //String value "CustomerPhone" calls getCustomerPhone method
PropertyValueFactory<Customer, String> custCountryFactory = new PropertyValueFactory<>("country");
PropertyValueFactory<Customer, String> custDivisionFactory = new PropertyValueFactory<>("division");
PropertyValueFactory<Customer, String> custAddressFactory = new PropertyValueFactory<>("address");
PropertyValueFactory<Customer, String> custPostalCodeFactory = new PropertyValueFactory<>("postalCode");
customerIDColumn.setCellValueFactory(custCustomerIDFactory);
customerNameColumn.setCellValueFactory(custNameFactory);
customerPhoneColumn.setCellValueFactory(custPhoneFactory);
customerCountryColumn.setCellValueFactory(custCountryFactory);
customerDivisionColumn.setCellValueFactory(custDivisionFactory);
customerAddressColumn.setCellValueFactory(custAddressFactory);
customerPostalCodeColumn.setCellValueFactory(custPostalCodeFactory);
Customer cust = new Customer();
cust.setCustomerID(result.getInt("Customer_ID"));
cust.setCustomerName(result.getString("Customer_Name"));
cust.setCustomerPhone(result.getString("Phone"));
cust.setCustomerAddress(result.getString("Address"));
cust.setCustomerPostalCode(result.getString("Postal_Code"));
cust.setCustomerDivision(result.getString("Division"));
cust.setCustomerCountry(result.getString("Country"));
customerOL.addAll(cust);
customerTable.setItems(customerOL);
the above is a part of java code. But I think it explains what I am trying to do.
The line customerOL.addAll(cust); adds 3 customer data into the customerOL object.
The Country, Division, etc all values are getting populated properly in the object. But when the table view is generated strangely I only see the values of ID and Customer Name being populated. The rest of the values are empty as could be seen below:
I am not sure what could be causing this. Here is the FXML file corresponding to this
<?xml version="1.0" encoding="UTF-8"?>
<?import javafx.scene.control.*?>
<?import javafx.scene.layout.*?>
<?import javafx.scene.text.Font?>
<AnchorPane fx:id="customerAddLabel" maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity"
minWidth="-Infinity" prefHeight="683.0" prefWidth="824.0"
style="-fx-background-color: silver; -fx-border-color: black; -fx-border-radius: 5;"
xmlns="http://javafx.com/javafx/10.0.1" xmlns:fx="http://javafx.com/fxml/1"
fx:controller="c195.View_Controller.CustomerScreenController">
<children>
<Label alignment="TOP_CENTER" layoutX="300.0" layoutY="14.0" prefHeight="38.0" prefWidth="226.0"
style="-fx-border-color: gray; -fx-border-radius: 5;" text="Customer" textAlignment="CENTER">
<font>
<Font name="System Bold Italic" size="25.0"/>
</font>
</Label>
<AnchorPane layoutX="16.0" layoutY="102.0" prefHeight="404.0" prefWidth="363.0"
style="-fx-background-color: white;">
<children>
<TableView fx:id="customerTable" layoutY="1.0" prefHeight="403.0" prefWidth="363.0"
style="-fx-border-color: black; -fx-border-radius: 5;">
<columns>
<TableColumn fx:id="customerIDColumn" prefWidth="63.0" text="ID"/>
<TableColumn fx:id="customerNameColumn" prefWidth="175.0" text="Customer Name"/>
<TableColumn fx:id="customerPhoneColumn" prefWidth="123.0" text="Phone"/>
<TableColumn fx:id="customerAddressColumn" prefWidth="123.0" text="Address"/>
<TableColumn fx:id="customerPostalCodeColumn" prefWidth="123.0" text="Postal Code"/>
<TableColumn fx:id="customerDivisionColumn" prefWidth="123.0" text="Division"/>
<TableColumn fx:id="customerCountryColumn" prefWidth="123.0" text="Country"/>
</columns>
</TableView>
</children>
</AnchorPane>
<TitledPane alignment="CENTER" animated="false" layoutX="413.0" layoutY="100.0" prefHeight="464.0"
prefWidth="374.0" text="Customer Details">
<content>
<GridPane prefHeight="292.0" prefWidth="373.0">
<columnConstraints>
<ColumnConstraints hgrow="SOMETIMES" maxWidth="172.2000732421875" minWidth="10.0"
prefWidth="99.80004272460937"/>
<ColumnConstraints hgrow="SOMETIMES" maxWidth="268.199951171875" minWidth="10.0"
prefWidth="253.39995727539065"/>
</columnConstraints>
<rowConstraints>
<RowConstraints minHeight="10.0" prefHeight="30.0" vgrow="SOMETIMES"/>
<RowConstraints minHeight="10.0" prefHeight="30.0" vgrow="SOMETIMES"/>
<RowConstraints minHeight="10.0" prefHeight="30.0" vgrow="SOMETIMES"/>
<RowConstraints minHeight="10.0" prefHeight="30.0" vgrow="SOMETIMES"/>
<RowConstraints minHeight="10.0" prefHeight="30.0" vgrow="SOMETIMES"/>
<RowConstraints minHeight="10.0" prefHeight="30.0" vgrow="SOMETIMES"/>
<RowConstraints minHeight="10.0" prefHeight="30.0" vgrow="SOMETIMES"/>
<RowConstraints minHeight="10.0" prefHeight="30.0" vgrow="SOMETIMES"/>
<RowConstraints minHeight="10.0" prefHeight="30.0" vgrow="SOMETIMES"/>
</rowConstraints>
<children>
<TextField fx:id="customerCustomerIDTextField" onAction="#CustomerCustomerIDTextFieldHandler"
GridPane.columnIndex="1" GridPane.rowIndex="1"/>
<Label fx:id="customerCustomerIDLabel" text="Customer ID" GridPane.rowIndex="1"/>
<Label fx:id="customerCustomerNameLabel" text="Company Name" GridPane.rowIndex="2"/>
<Label fx:id="customerAddressLabel" text="Address" GridPane.rowIndex="4"/>
<Label fx:id="customerAddress2Label" text="POC" GridPane.rowIndex="3"/>
<Label fx:id="customerCityLabel" text="City" GridPane.rowIndex="5"/>
<Label fx:id="customerCountryLabel" text="Country" GridPane.rowIndex="6"/>
<Label fx:id="customerPostalCodeLabel" text="Postal Code" GridPane.rowIndex="7"/>
<Label fx:id="customerPhoneLabel" text="Phone No." GridPane.rowIndex="8"/>
<TextField fx:id="customerCustomerNameTextField"
onAction="#CustomerCustomerNameTextFieldHandler" GridPane.columnIndex="1"
GridPane.rowIndex="2"/>
<TextField fx:id="customerAddressTextField" onAction="#CustomerAddressTextFieldHandler"
GridPane.columnIndex="1" GridPane.rowIndex="4"/>
<TextField fx:id="customerAddress2TextField" onAction="#CustomerAddress2TextFieldHandler"
GridPane.columnIndex="1" GridPane.rowIndex="3"/>
<ComboBox fx:id="customerCityComboBox" onAction="#CustomerCityComboBoxHandler" prefHeight="26.0"
prefWidth="252.0" GridPane.columnIndex="1" GridPane.rowIndex="5"/>
<ComboBox fx:id="customerCountryComboBox" onAction="#CustomerCountryComboBoxHandler"
prefHeight="26.0" prefWidth="252.0" GridPane.columnIndex="1" GridPane.rowIndex="6"/>
<TextField fx:id="customerPostalCodeTextField" onAction="#CustomerPostalCodeTextFieldHandler"
GridPane.columnIndex="1" GridPane.rowIndex="7"/>
<TextField fx:id="customerPhoneTextField" onAction="#CustomerPhoneTextFieldHandler"
GridPane.columnIndex="1" GridPane.rowIndex="8"/>
<HBox alignment="CENTER_LEFT" prefHeight="100.0" prefWidth="200.0" spacing="20.0"
GridPane.columnIndex="1">
<children>
<RadioButton fx:id="customerActiveRadioButton" mnemonicParsing="false"
onAction="#CustomerActiveRadioButtonHandler" text="Active"/>
<RadioButton fx:id="customerInactiveRadioButton" mnemonicParsing="false"
onAction="#CustomerInactiveRadioButtonHandler" text="Inactive"/>
</children>
</HBox>
</children>
</GridPane>
</content>
</TitledPane>
<ButtonBar layoutX="587.0" layoutY="564.0" prefHeight="40.0" prefWidth="200.0">
<buttons>
<Button fx:id="customerSaveButton" minWidth="66.0" mnemonicParsing="false"
onAction="#CustomerSaveButtonHandler" prefHeight="26.0" text="Save"/>
<Button fx:id="customerCancelButton" mnemonicParsing="false" onAction="#CustomerCancelButtonHandler"
text="Cancel"/>
</buttons>
</ButtonBar>
<ButtonBar layoutX="500.0" layoutY="613.0" prefHeight="40.0" prefWidth="200.0">
<buttons>
<Button fx:id="customerBackButton" mnemonicParsing="false" onAction="#CustomerBackButtonHandler"
text="Back"/>
<Button fx:id="customerAddButton" mnemonicParsing="false" onAction="#CustomerAddButtonHandler"
text="Add"/>
<Button fx:id="customerDeleteButton" mnemonicParsing="false" onAction="#CustomerDeleteButtonHandler"
text="Delete"/>
</buttons>
</ButtonBar>
<Label fx:id="customerLabel" layoutX="542.0" layoutY="52.0" prefHeight="40.0" prefWidth="90.0"
textFill="#1924e8">
<font>
<Font name="System Bold Italic" size="20.0"/>
</font>
</Label>
<Label layoutX="34.0" layoutY="517.0" prefHeight="27.0" prefWidth="327.0"
text="Click on Customer in Table to Update" textFill="#eb0c13">
<font>
<Font name="System Bold Italic" size="18.0"/>
</font>
</Label>
</children>
</AnchorPane>
I am not sure how to debug this. As the values in the ObservableList<Customer> are getting populated properly, it just doesn't appear in the TableView.
Here is the Customer class:
public class Customer {
private int customerID; //Auto incremented in database
private String customerName;
private int active;
private Date createDate;
private String createdBy;
private String address;
private String address2;
private String division;
private String postalCode;
private String phone;
private String country;
private Date lastUpdate;
private String lastUpdateBy;
public Customer() {
}
public Customer(int customerID, String customerName, int active, String address, String address2, String division, String postalCode, String phone, String country, Date lastUpdate, String lastUpdateBy) {
setCustomerID(customerID);
setCustomerName(customerName);
setCustomerActive(active);
setCustomerAddress(address);
setCustomerAddress2(address2);
setCustomerDivision(division);
setCustomerPostalCode(postalCode);
setCustomerPhone(phone);
setCustomerCountry(country);
setCustomerLastUpdate(lastUpdate);
setCustomerLastUpdateBy(lastUpdateBy);
}
public Customer(int customerID, String customerName) {
setCustomerID(customerID); //this is Auto Incremented in the database
setCustomerName(customerName);
}
public int getCustomerID() {
return customerID;
}
public String getCustomerName() {
return customerName;
}
public int getCustomerActive() {
return active;
}
public String getCustomerAddress() {
return address;
}
public String getCustomerAddress2() {
return address2;
}
public String getCustomerCity() {
return division;
}
public String getCustomerPostalCode() {
return postalCode;
}
public String getCustomerPhone() {
return phone;
}
public String getCustomerCountry() {
return country;
}
public Date getCustomerLastUpdate() {
return lastUpdate;
}
public String getCustomerLastUpdateBy() {
return lastUpdateBy;
}
public void setCustomerID(int customerID) {
this.customerID = customerID;
}
public void setCustomerName(String customerName) {
this.customerName = customerName;
}
public void setCustomerActive(int active) {
this.active = active;
}
public void setCustomerAddress(String address) {
this.address = address;
}
public void setCustomerAddress2(String address2) {
this.address2 = address2;
}
public void setCustomerDivision(String city) {
this.division = city;
}
public void setCustomerPostalCode(String postalCode) {
this.postalCode = postalCode;
}
public void setCustomerPhone(String phone) {
this.phone = phone;
}
public void setCustomerCountry(String country) {
this.country = country;
}
public void setCustomerLastUpdate(Date lastUpdate) {
this.lastUpdate = lastUpdate;
}
public void setCustomerLastUpdateBy(String lastUpdateBy) {
this.lastUpdateBy = lastUpdateBy;
}
}

JFXDatePicker not working when program is exported to a jar file

I have a application which uses two JFXDatePickers from JFoenix. They work perfectly when running from Eclipse but do not work when I export the program to a JAR file. They still return the text that is set by default but when I try to select a date using it the window freezes and the application does not respond.
I've searched trough stackoverflow and javafx and jfoenix documentation but can't seem to find an answer. Can someone please help me? This is for a school project. Any suggestions?
#FXML
private JFXDatePicker startDatePicker;
#FXML
private JFXDatePicker endDatePicker;
#FXML
private void initialize() {
this.endDatePicker.setValue(LocalDate.now());
this.startDatePicker.setValue(LocalDate.now().withDayOfMonth(1));
}
Thank you very much!
Edit: Thank you for the suggestion, Slaw. I've launched it trough the command line and didn't get any exceptions. The controller class where the error happens is this one:
package application;
import java.time.LocalDate;
import com.jfoenix.controls.JFXDatePicker;
import javafx.event.ActionEvent;
import javafx.fxml.FXML;
import javafx.scene.control.Alert;
import javafx.scene.control.Button;
public class SeeAllQuotesFilterScreenController {
#FXML
private Button cancelButton;
#FXML
private Button enterButton;
#FXML
private JFXDatePicker startDatePicker;
#FXML
private JFXDatePicker endDatePicker;
#FXML
private void initialize() {
this.endDatePicker.setValue(LocalDate.now());
this.startDatePicker.setValue(LocalDate.now().withDayOfMonth(1));
}
#FXML
void cancelButtonClicked(ActionEvent event) {
new Alert(Alert.AlertType.INFORMATION, "changes to a different screen on the complete application").showAndWait();
}
#FXML
void enterButtonClicked(ActionEvent event) {
new Alert(Alert.AlertType.INFORMATION, "changes to a different screen on the complete application").showAndWait();
}
}
Also, the fxml:
<?xml version="1.0" encoding="UTF-8"?>
<?import com.jfoenix.controls.JFXButton?>
<?import com.jfoenix.controls.JFXDatePicker?>
<?import javafx.geometry.Insets?>
<?import javafx.scene.layout.BorderPane?>
<?import javafx.scene.layout.HBox?>
<?import javafx.scene.layout.VBox?>
<?import javafx.scene.text.Font?>
<?import javafx.scene.text.Text?>
<BorderPane style="-fx-background-color: #E2FAFE;" xmlns="http://javafx.com/javafx/8.0.171" xmlns:fx="http://javafx.com/fxml/1" fx:controller="application.SeeAllQuotesFilterScreenController">
<center>
<BorderPane prefHeight="500.0" prefWidth="500.0" BorderPane.alignment="CENTER">
<center>
<VBox alignment="TOP_CENTER">
<children>
<Text strokeType="OUTSIDE" strokeWidth="0.0" text="Please choose the search criteria below.">
<VBox.margin>
<Insets left="5.0" right="5.0" top="5.0" />
</VBox.margin>
</Text>
<HBox alignment="CENTER">
<children>
<JFXDatePicker fx:id="startDatePicker" promptText="Start Date">
<HBox.margin>
<Insets bottom="12.0" left="12.0" right="12.0" top="12.0" />
</HBox.margin>
</JFXDatePicker>
<JFXDatePicker fx:id="endDatePicker" promptText="End Date">
<HBox.margin>
<Insets bottom="12.0" left="12.0" right="12.0" top="12.0" />
</HBox.margin>
</JFXDatePicker>
</children>
<padding>
<Insets bottom="40.0" top="40.0" />
</padding>
</HBox>
<JFXButton fx:id="enterButton" onAction="#enterButtonClicked" text="Enter">
<VBox.margin>
<Insets bottom="20.0" left="20.0" right="20.0" />
</VBox.margin></JFXButton>
</children>
<padding>
<Insets bottom="3.0" left="5.0" right="3.0" top="30.0" />
</padding>
</VBox>
</center>
</BorderPane>
</center>
<top>
<HBox alignment="CENTER" prefHeight="37.0" prefWidth="500.0" BorderPane.alignment="CENTER">
<children>
<HBox alignment="CENTER_LEFT" HBox.hgrow="NEVER">
<children>
<JFXButton fx:id="cancelButton" onAction="#cancelButtonClicked" prefHeight="25.0" prefWidth="54.0" text="Cancel" />
</children>
</HBox>
<HBox>
<children>
<Text strokeType="OUTSIDE" strokeWidth="0.0" text="Search Criteria">
<font>
<Font size="18.0" />
</font>
<HBox.margin>
<Insets bottom="12.0" left="12.0" right="12.0" top="12.0" />
</HBox.margin>
</Text>
</children>
</HBox>
</children>
</HBox>
</top>
</BorderPane>
My Main():
package application;
import javafx.application.Application;
import javafx.fxml.FXMLLoader;
import javafx.stage.Stage;
import javafx.scene.Scene;
import javafx.scene.layout.BorderPane;
public class Main extends Application {
#Override
public void start(Stage primaryStage) {
try {
BorderPane root = (BorderPane) FXMLLoader.load(getClass().getResource("SeeAllQuotesFilterScreen.fxml"));
Scene scene = new Scene(root, 500, 600);
primaryStage.setScene(scene);
primaryStage.show();
} catch (Exception e) {
e.printStackTrace();
}
}
public void initialize() {
}
public static void main(String[] args) {
launch(args);
}
}
I appreciate all and any help!

JavaFx 12 : About stages

I wonder if you can do this:
a main stage of the content
and a menu stage within that content stage
like this:
enter image description here
i try make but i got this:
enter image description here
my fxml:
<StackPane fx:id="root" prefWidth="311.0" xmlns="http://javafx.com/javafx/8.0.171" xmlns:fx="http://javafx.com/fxml/1" fx:controller="com.semeq.controllers.Test">
<!-- Header -->
<BorderPane>
<top>
<VBox spacing="20">
<JFXToolbar>
<leftItems>
<JFXRippler maskType="CIRCLE" style="-fx-ripple-color:WHITE;">
<StackPane fx:id="titleBurgerContainer">
<JFXHamburger fx:id="titleBurger">
<HamburgerBackArrowBasicTransition />
</JFXHamburger>
</StackPane>
</JFXRippler>
<Label>Material Design</Label>
</leftItems>
</JFXToolbar>
</VBox>
</top>
<!-- Content Area -->
<center>
<JFXDrawer fx:id="drawer" defaultDrawerSize="250" direction="LEFT">
<styleClass>
<String fx:value="body" />
</styleClass>
</JFXDrawer>
</center>
</BorderPane>
</StackPane>
controller:
package com.semeq.controllers;
import java.io.IOException;
import org.springframework.stereotype.Controller;
import com.jfoenix.controls.JFXDrawer;
import com.jfoenix.controls.JFXHamburger;
import com.jfoenix.controls.JFXRippler;
import com.jfoenix.transitions.hamburger.HamburgerBackArrowBasicTransition;
import javafx.fxml.FXML;
import javafx.fxml.FXMLLoader;
import javafx.scene.Node;
import javafx.scene.input.MouseEvent;
import javafx.scene.layout.Pane;
import javafx.scene.layout.StackPane;
import javafx.scene.layout.VBox;
#Controller
public class Test {
#FXML
private Pane root;
#FXML
private StackPane titleBurgerContainer;
#FXML
private JFXHamburger titleBurger;
#FXML
private JFXRippler optionsRippler;
#FXML
private StackPane optionsBurger;
#FXML
private VBox box;
#FXML
private JFXDrawer drawer;
public void initialize() {
try {
box = FXMLLoader.load(getClass().getResource("/Home.fxml"));
drawer.setSidePane(box);
for (Node node : box.getChildren()) {
if(node.getAccessibleText() != null) {
System.out.println("xdasdd");
node.addEventHandler(MouseEvent.MOUSE_CLICKED, (ex) -> {
switch(node.getAccessibleText()) {
case "Gerenciar" :
try {
StackPane gerenciar = FXMLLoader.load(getClass().getResource("/Gerenciar.fxml"));
root.getChildren().addAll(gerenciar);
} catch (IOException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
break;
}
});
}
}
} catch (IOException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
HamburgerBackArrowBasicTransition transition = new HamburgerBackArrowBasicTransition(titleBurger);
drawer.setOnDrawerOpening(e -> {
transition.setRate(1);
transition.play();
});
drawer.setOnDrawerClosing(e -> {
transition.setRate(-1);
transition.play();
});
titleBurgerContainer.setOnMouseClicked(e -> {
if (drawer.isClosed() || drawer.isClosing()) {
drawer.open();
} else {
drawer.close();
}
});
}
}
i don't know if this is possible
a stage for all the content
and a stage for the menu within that content
In other words, I wanted a Main Stage
and another stage being part of this main stage and when you clicked on the main stage it would appear
Sorry to say, but you are doing it all wrong. You are making everything very complex. Whenever you work with JFXDrawer. Try to make a seperate fxml file for the drawer itself, and another fxml file for the root container, where you want your drawer to be placed. In this way you will have two fxml files. It will make things much simpler.
Here's my approach for your problem. I hope it helps you!
Main.java (Main launch file) -
package application;
import javafx.application.Application;
import javafx.fxml.FXMLLoader;
import javafx.stage.Stage;
import javafx.scene.Parent;
import javafx.scene.Scene;
public class Main extends Application {
#Override
public void start(Stage primaryStage) {
try {
//this is the directory - package_name/fxml_file.fxml
Parent root =
FXMLLoader.load(getClass().getResource("/application/container.fxml"));
Scene scene = new Scene(root);
primaryStage.setScene(scene);
primaryStage.setTitle("Material Design JFX Navigation Drawer");
primaryStage.show();
} catch(Exception e) {
e.printStackTrace();
}
}
public static void main(String[] args) {
launch(args);
}
}
NavigationController.java (Controller Class) -
public class NavigationController implements Initializable {
#FXML private AnchorPane anchorPane;
#FXML private StackPane stackPane1, stackPane2, stackPane3, stackPane4;
#FXML private JFXHamburger hamburger;
#FXML private JFXDrawer drawer;
#Override
public void initialize(URL arg0, ResourceBundle arg1) {
StackPane[] stackPaneArray = {stackPane1, stackPane2, stackPane3, stackPane4};
for(int i = 0;i<stackPaneArray.length;i++){
stackPaneArray[i].setVisible(false);;
}
try {
VBox box = FXMLLoader.load(getClass().getResource("/application/drawer.fxml")); //this is the directory - package_name/fxml_file.fxml
drawer.setSidePane(box);
for(Node node : box.getChildren()){
if(node.getAccessibleText()!=null){
node.addEventHandler(MouseEvent.MOUSE_CLICKED, (e) ->{
switch(node.getAccessibleText()){
case "Gerenciar_1":
stackPane1.setVisible(true);
stackPane2.setVisible(false);
stackPane3.setVisible(false);
stackPane4.setVisible(false);
break;
case "Gerenciar_2":
stackPane1.setVisible(false);
stackPane2.setVisible(true);
stackPane3.setVisible(false);
stackPane4.setVisible(false);
break;
case "Gerenciar_3":
stackPane1.setVisible(false);
stackPane2.setVisible(false);
stackPane3.setVisible(true);
stackPane4.setVisible(false);
break;
case "Gerenciar_4":
stackPane1.setVisible(false);
stackPane2.setVisible(false);
stackPane3.setVisible(false);
stackPane4.setVisible(true);
break;
}
});
}
}
HamburgerBackArrowBasicTransition transition = new HamburgerBackArrowBasicTransition(hamburger);
transition.setRate(-1);
hamburger.addEventHandler(MouseEvent.MOUSE_PRESSED,(e) -> {
transition.setRate(transition.getRate()*-1);
transition.play();
if(drawer.isShown()){
drawer.close();
}else{
drawer.open();
}
});
} catch (IOException e1) {
e1.printStackTrace();
}
}
}
container.fxml (fxml file for the container) -
<?xml version="1.0" encoding="UTF-8"?>
<?import com.jfoenix.controls.JFXDrawer?>
<?import com.jfoenix.controls.JFXHamburger?>
<?import javafx.scene.control.Menu?>
<?import javafx.scene.control.MenuBar?>
<?import javafx.scene.layout.AnchorPane?>
<AnchorPane fx:id="anchorPane" maxHeight="-Infinity" maxWidth="-Infinity"
minHeight="-Infinity" minWidth="-Infinity" prefHeight="390.0"
prefWidth="460.0" xmlns="http://javafx.com/javafx/8.0.102"
xmlns:fx="http://javafx.com/fxml/1"
fx:controller="application.NavigationController">
<children>
<JFXDrawer fx:id="drawer" defaultDrawerSize="173.0" layoutY="24.0"
prefHeight="367.0" prefWidth="100.0" />
<MenuBar prefHeight="25.0" prefWidth="460.0">
<menus>
<Menu mnemonicParsing="false">
<graphic>
<JFXHamburger fx:id="hamburger" />
</graphic>
</Menu>
</menus>
</MenuBar>
<StackPane fx:id="stackPane1" layoutX="140.0" layoutY="25.0" prefHeight="367.0" prefWidth="320.0">
<children>
<Label text="StackPane 1">
<font>
<Font name="System Bold" size="17.0" />
</font>
</Label>
</children></StackPane>
<StackPane fx:id="stackPane2" layoutX="140.0" layoutY="25.0" prefHeight="367.0" prefWidth="320.0">
<children>
<Label text="StackPane 2">
<font>
<Font name="System Bold" size="17.0" />
</font>
</Label>
</children></StackPane>
<StackPane fx:id="stackPane3" layoutX="140.0" layoutY="25.0" prefHeight="367.0" prefWidth="320.0">
<children>
<Label text="StackPane 3">
<font>
<Font name="System Bold" size="17.0" />
</font>
</Label>
</children></StackPane>
<StackPane fx:id="stackPane4" layoutX="140.0" layoutY="25.0" prefHeight="367.0" prefWidth="320.0">
<children>
<Label text="StackPane 4">
<font>
<Font name="System Bold" size="17.0" />
</font>
</Label>
</children></StackPane>
</children>
</AnchorPane>
drawer.fxml (fxml file for the drawer) -
<?xml version="1.0" encoding="UTF-8"?>
<?import com.jfoenix.controls.JFXButton?>
<?import de.jensd.fx.glyphs.fontawesome.FontAwesomeIconView?>
<?import javafx.scene.layout.VBox?>
<?import javafx.scene.text.Font?>
<VBox alignment="TOP_RIGHT" maxHeight="-Infinity" maxWidth="-Infinity"
minHeight="-Infinity" minWidth="-Infinity" prefHeight="390.0"
prefWidth="173.0" xmlns="http://javafx.com/javafx/8.0.102"
xmlns:fx="http://javafx.com/fxml/1">
<children>
<JFXButton accessibleText="Gerenciar_1" buttonType="RAISED"
focusTraversable="false" prefHeight="57.0" prefWidth="176.0"
text="Gerenciar">
<font>
<Font size="15.0" />
</font>
<graphic>
<FontAwesomeIconView glyphName="USER" size="30" wrappingWidth="43.0" />
</graphic>
</JFXButton>
<JFXButton accessibleText="Gerenciar_2" buttonType="RAISED"
focusTraversable="false" prefHeight="57.0" prefWidth="178.0"
text="Gerenciar">
<font>
<Font size="15.0" />
</font>
<graphic>
<FontAwesomeIconView glyphName="USER" size="30" wrappingWidth="43.0" />
</graphic>
</JFXButton>
<JFXButton accessibleText="Gerenciar_3" buttonType="RAISED"
focusTraversable="false" prefHeight="57.0" prefWidth="178.0"
text="Gerenciar">
<font>
<Font size="15.0" />
</font>
<graphic>
<FontAwesomeIconView glyphName="USER" size="30" wrappingWidth="43.0" />
</graphic>
</JFXButton>
<JFXButton accessibleText="Gerenciar_4" buttonType="RAISED"
focusTraversable="false" prefHeight="57.0" prefWidth="178.0"
text="Gerenciar">
<font>
<Font size="15.0" />
</font>
<graphic>
<FontAwesomeIconView glyphName="USER" size="30" wrappingWidth="43.0" />
</graphic>
</JFXButton>
</children>
</VBox>
Here's the screenshot of what I did -
Take a look. I hope it solves your problem.

JavaFX: How can another tab(containing a textarea) be added when a new user is added?

In this simple JavaFX application, when a new user is added, text that says "New User added" is printed into a text area in the first tab. How can an additional tab be added and text "New User added" printed into a text area in it each time a new user is added?
Any help would be greatly appreciated.
View > PersonOverview.fxml
<?xml version="1.0" encoding="UTF-8"?>
<?import javafx.geometry.*?>
<?import javafx.scene.control.*?>
<?import java.lang.*?>
<?import javafx.scene.layout.*?>
<HBox xmlns="http://javafx.com/javafx/8.0.40" xmlns:fx="http://javafx.com/fxml/1" fx:controller="ch.makery.address.PersonOverviewController">
<children>
<TableView fx:id="personTable" prefHeight="298.0" prefWidth="246.0">
<columns>
<TableColumn fx:id="firstNameColumn" prefWidth="75.0" text="First Name" />
<TableColumn fx:id="lastNameColumn" prefWidth="75.0" text="Last Name" />
</columns>
</TableView>
<VBox prefHeight="298.0" prefWidth="271.0">
<children>
<AnchorPane prefHeight="284.0" prefWidth="227.0">
<children>
<Label layoutX="9.0" layoutY="4.0" prefHeight="19.0" prefWidth="96.0" text="Person Details" />
<GridPane layoutX="108.0" layoutY="121.0" AnchorPane.leftAnchor="5.0" AnchorPane.rightAnchor="5.0" AnchorPane.topAnchor="30.0">
<columnConstraints>
<ColumnConstraints hgrow="SOMETIMES" minWidth="10.0" prefWidth="100.0" />
<ColumnConstraints hgrow="SOMETIMES" minWidth="10.0" prefWidth="100.0" />
</columnConstraints>
<rowConstraints>
<RowConstraints minHeight="10.0" prefHeight="30.0" vgrow="SOMETIMES" />
<RowConstraints minHeight="10.0" prefHeight="30.0" vgrow="SOMETIMES" />
<RowConstraints minHeight="10.0" prefHeight="30.0" vgrow="SOMETIMES" />
<RowConstraints minHeight="10.0" prefHeight="30.0" vgrow="SOMETIMES" />
<RowConstraints minHeight="10.0" prefHeight="30.0" vgrow="SOMETIMES" />
<RowConstraints minHeight="10.0" prefHeight="30.0" vgrow="SOMETIMES" />
</rowConstraints>
<children>
<Label text="First Name" />
<Label text="Last Name" GridPane.rowIndex="1" />
<Label text="Street" GridPane.rowIndex="2" />
<Label text="City" GridPane.rowIndex="3" />
<Label text="Postal Code" GridPane.rowIndex="4" />
<Label text="Birthday" GridPane.rowIndex="5" />
<Label fx:id="firstNameLabel" text="Label" GridPane.columnIndex="1" />
<Label fx:id="lastNameLabel" text="Label" GridPane.columnIndex="1" GridPane.rowIndex="1" />
<Label fx:id="streetLabel" text="Label" GridPane.columnIndex="1" GridPane.rowIndex="2" />
<Label fx:id="cityLabel" text="Label" GridPane.columnIndex="1" GridPane.rowIndex="3" />
<Label fx:id="postalCodeLabel" text="Label" GridPane.columnIndex="1" GridPane.rowIndex="4" />
<Label fx:id="birthdayLabel" text="Label" GridPane.columnIndex="1" GridPane.rowIndex="5" />
</children>
</GridPane>
<ButtonBar buttonMinWidth="50.0" layoutX="14.0" layoutY="244.0" prefHeight="40.0" prefWidth="200.0">
<buttons>
<Button mnemonicParsing="false" onAction="#handleNewPerson" text="New" />
<Button mnemonicParsing="false" onAction="#handleEditPerson" text="Edit" />
<Button mnemonicParsing="false" onAction="#handleDeletePerson" text="Delete" />
</buttons>
</ButtonBar>
</children>
<VBox.margin>
<Insets />
</VBox.margin>
</AnchorPane>
</children>
</VBox>
<TabPane prefHeight="296.0" prefWidth="337.0" tabClosingPolicy="UNAVAILABLE">
<tabs>
<Tab>
<content>
<TextArea fx:id="textArea" prefHeight="264.0" prefWidth="302.0" />
</content>
</Tab>
</tabs>
</TabPane>
</children>
</HBox>
View > PersonOverviewController
package ch.makery.address;
import ch.makery.address.util.DateUtil;
import javafx.fxml.FXML;
import javafx.scene.control.*;
import ch.makery.address.MainApp;
import ch.makery.address.model.Person;
public class PersonOverviewController {
#FXML
private TableView<Person> personTable;
#FXML
private TableColumn<Person, String> firstNameColumn;
#FXML
private TableColumn<Person, String> lastNameColumn;
#FXML
private Label firstNameLabel;
#FXML
private Label lastNameLabel;
#FXML
private Label streetLabel;
#FXML
private Label postalCodeLabel;
#FXML
private Label cityLabel;
#FXML
private Label birthdayLabel;
#FXML
private TextArea textArea;
// Reference to the main application.
private MainApp mainApp;
/**
* The constructor.
* The constructor is called before the initialize() method.
*/
public PersonOverviewController() {
}
/**
* Initializes the controller class. This method is automatically called
* after the fxml file has been loaded.
*/
#FXML
private void initialize() {
// Initialize the person table with the two columns.
firstNameColumn.setCellValueFactory(
cellData -> cellData.getValue().firstNameProperty());
lastNameColumn.setCellValueFactory(
cellData -> cellData.getValue().lastNameProperty());
// Clear person details.
showPersonDetails(null);
// Listen for selection changes and show the person details when changed.
personTable.getSelectionModel().selectedItemProperty().addListener(
(observable, oldValue, newValue) -> showPersonDetails(newValue));
}
/**
* Is called by the main application to give a reference back to itself.
*
* #param mainApp
*/
public void setMainApp(MainApp mainApp) {
this.mainApp = mainApp;
// Add observable list data to the table
personTable.setItems(mainApp.getPersonData());
}
/**
* Fills all text fields to show details about the person.
* If the specified person is null, all text fields are cleared.
*
* #param person the person or null
*/
private void showPersonDetails(Person person) {
if (person != null) {
// Fill the labels with info from the person object.
firstNameLabel.setText(person.getFirstName());
lastNameLabel.setText(person.getLastName());
streetLabel.setText(person.getStreet());
postalCodeLabel.setText(Integer.toString(person.getPostalCode()));
cityLabel.setText(person.getCity());
birthdayLabel.setText(DateUtil.format(person.getBirthday()));
// birthdayLabel.setText(...);
} else {
// Person is null, remove all the text.
firstNameLabel.setText("");
lastNameLabel.setText("");
streetLabel.setText("");
postalCodeLabel.setText("");
cityLabel.setText("");
birthdayLabel.setText("");
}
}
public void print(String message) {
textArea.appendText(message);
}
/**
* Called when the user clicks on the delete button.
*/
#FXML
private void handleDeletePerson() {
int selectedIndex = personTable.getSelectionModel().getSelectedIndex();
if (selectedIndex >= 0) {
personTable.getItems().remove(selectedIndex);
} else {
// Nothing selected.
Alert alert = new Alert(Alert.AlertType.WARNING);
alert.initOwner(mainApp.getPrimaryStage());
alert.setTitle("No Selection");
alert.setHeaderText("No Person Selected");
alert.setContentText("Please select a person in the table.");
alert.showAndWait();
}
}
/**
* Called when the user clicks the new button. Opens a dialog to edit
* details for a new person.
*/
#FXML
private void handleNewPerson() {
Person tempPerson = new Person();
boolean okClicked = mainApp.showPersonEditDialog(tempPerson);
if (okClicked) {
mainApp.getPersonData().add(tempPerson);
print("New User added");
}
}
/**
* Called when the user clicks the edit button. Opens a dialog to edit
* details for the selected person.
*/
#FXML
private void handleEditPerson() {
Person selectedPerson = personTable.getSelectionModel().getSelectedItem();
if (selectedPerson != null) {
boolean okClicked = mainApp.showPersonEditDialog(selectedPerson);
if (okClicked) {
showPersonDetails(selectedPerson);
}
} else {
// Nothing selected.
Alert alert = new Alert(Alert.AlertType.WARNING);
alert.initOwner(mainApp.getPrimaryStage());
alert.setTitle("No Selection");
alert.setHeaderText("No Person Selected");
alert.setContentText("Please select a person in the table.");
alert.showAndWait();
}
}
}
In you're handleNewPerson method, you would have to add something like:
Tab tab = new Tab();
tab.setText("TabText");
TextArea ta = new TextArea("New User added");
tab.setContent(ta);
tabPan.getTabs().add(tab);
And add add:
#FXML
private TabPane tabPan;
And in the fxml add
fx:id="tabPan"
To the TabPane
Now I have not been able to test your program due to your program requires a lot of the other classes. But you can also see a good example of somthing similar her.

trying to display objects on JAVAFX table and i am getting java.lang.NullPointerException

i am having issue with lines 112/113/114 the program will compile without them,
am trying to get the the data from (ObservableList database) and display it on the table, i try to keep the variables as date,double. changed them to SimpleDoubleProperty, SimpleObjectProperty.
this is the exception am getting
at com.sun.glass.ui.win.WinApplication.lambda$null$145(Unknown
Source) at
com.sun.glass.ui.win.WinApplication$$Lambda$36/2117255219.run(Unknown
Source) ... 1 more Caused by: java.lang.NullPointerException at
org.xcellcomm.Controller.initialize(Controller.java:103) ... 23 more
Exception running application org.xcellcomm.Start
package org.xcellcomm;
import java.net.URL;
import java.util.ArrayList;
import java.util.Date;
import java.util.ResourceBundle;
import javafx.beans.property.SimpleDoubleProperty;
import javafx.beans.property.SimpleObjectProperty;
import javafx.beans.property.SimpleStringProperty;
import javafx.collections.FXCollections;
import javafx.collections.ObservableList;
import javafx.fxml.FXML;
import javafx.fxml.Initializable;
import javafx.scene.control.RadioButton;
import javafx.scene.control.TableColumn;
import javafx.scene.control.TableView;
import javafx.scene.control.ToggleGroup;
import javafx.scene.control.Alert;
import javafx.scene.control.Alert.AlertType;
import javafx.scene.control.cell.PropertyValueFactory;
import javafx.scene.control.Button;
import javafx.scene.control.CheckBox;
import javafx.scene.control.TextField;
public class Controller implements Initializable {
private final ObservableList<Mrc> data =
FXCollections.observableArrayList();
Date date;
ArrayList<Mrc> dailyMRC;
final static int VALUEBUNDLE = 5;
final static int PHP = 6;
final static int BLOCKIT = 1;
final static int RHAPSODY = 10;
final static int WORLDCALLING = 5;
final static int LOOKOUT = 3;
#FXML
private CheckBox checkboxFeatureLookout;
#FXML
private RadioButton plan40Radio;
#FXML
private CheckBox checkboxBlockIt;
#FXML
private CheckBox checkboxFeatureValueBundle;
#FXML
private TextField textfeildTodayGoal;
#FXML
private Button buttonAddActivation;
#FXML
private CheckBox checkboxFeatureRhpsody;
#FXML
private CheckBox checkboxFeatureWorldCalling;
#FXML
private RadioButton plan50Radio;
#FXML
private CheckBox checkboxFeaturePhp;
#FXML
private RadioButton plan60Radio;
#FXML
private TextField textfeildTodayActivations;
#FXML
private TableView<Plana> dailyActivationTable;
#FXML
private TableColumn<Plana, Date> dailyActivationTimeColon;
#FXML
private TableColumn<Plana, Double> dailyActivationPlanColon;
private final ObservableList<Plana> database =
FXCollections.observableArrayList();
#Override
public void initialize(URL location, ResourceBundle resources) {
dailyActivationPlanColon = new TableColumn<Controller.Plana, Double>();
dailyActivationTimeColon = new TableColumn<Controller.Plana, Date>();
dailyActivationTable.getColumns().addAll(dailyActivationPlanColon,dailyActivationTimeColon);
dailyMRC = new ArrayList<>();
ToggleGroup group = new ToggleGroup();
plan40Radio.setToggleGroup(group);
plan50Radio.setToggleGroup(group);
plan60Radio.setToggleGroup(group);
dailyActivationPlanColon.setCellValueFactory(new PropertyValueFactory<Plana, Double>("PlanProperty"));
dailyActivationTimeColon.setCellValueFactory(new PropertyValueFactory<Plana,Date>("dateProperty"));
dailyActivationTable.setItems(database);
}
//Getting input from the GUI and Calculate the MRC Constructor
private int newActivationCalculater(){
int mrc=0;
if(plan40Radio.isSelected())mrc=+40;
if(plan50Radio.isSelected())mrc=+50;
if(plan60Radio.isSelected())mrc=+60;
if(checkboxBlockIt.isSelected())mrc=+BLOCKIT;
if(checkboxFeatureLookout.isSelected())mrc=+LOOKOUT;
if(checkboxFeaturePhp.isSelected())mrc=+PHP;
if(checkboxFeatureRhpsody.isSelected())mrc=+RHAPSODY;
if(checkboxFeatureValueBundle.isSelected())mrc=+VALUEBUNDLE;
if(checkboxFeatureWorldCalling.isSelected())mrc=+WORLDCALLING;
return mrc;
}
//Getting the Current time for the mrc constructor
private Date currentTime(){
Date date = new Date();
return date;
}
public void buttonAddActivationPressed(){
if(plan40Radio.isSelected()||plan50Radio.isSelected()||plan60Radio.isSelected()){
double mrc = (double)newActivationCalculater();
Date date = currentTime();
//Mrc newactivation = ;
unselectAllItem();
database.add(new Plana((int)mrc, date));
todayactivationRefresh();
}//if end
else{//if user did not select plan
Alert alert = new Alert(AlertType.WARNING);
alert.setTitle("Warning!");
alert.setHeaderText("Something wrong:)");
alert.setContentText("You didn't select a Plan");
alert.showAndWait();}
}
void todayactivationRefresh(){
String todayactivation=dailyMRC.size()+"";
textfeildTodayActivations.setText(todayactivation);
}
void unselectAllItem(){
plan40Radio.setSelected(false);
plan50Radio.setSelected(false);
plan60Radio.setSelected(false);
checkboxBlockIt.setSelected(false);
checkboxFeatureLookout.setSelected(false);
checkboxFeaturePhp.setSelected(false);
checkboxFeatureValueBundle.setSelected(false);
checkboxFeatureWorldCalling.setSelected(false);
checkboxFeatureRhpsody.setSelected(false);
}
public class Plana {// its might not work because it is it's not public
// private final SimpleStringProperty dateStringProperty;
private final SimpleDoubleProperty PlanProperty;
private final SimpleObjectProperty<Date> dateProperty;
private Plana( double gPlan, Date gDate) {
// this.dateStringProperty = new SimpleStringProperty(gStringDate);
this.PlanProperty = new SimpleDoubleProperty(gPlan);
this.dateProperty = new SimpleObjectProperty<Date>(gDate);
}
/**
* #return the dateStringProperty
*/
// public SimpleStringProperty getDateStringProperty() {
// return dateStringProperty;
//}
/**
* #return the planProperty
*/
public SimpleDoubleProperty getPlanProperty() {
return PlanProperty;
}
/**
* #return the dateProperty
*/
public SimpleObjectProperty<Date> getDateProperty() {
return dateProperty;
}
}
}
and here is the startclass:
package org.xcellcomm;
import java.util.Date;
import javafx.application.Application;
import javafx.beans.property.SimpleDoubleProperty;
import javafx.beans.property.SimpleObjectProperty;
import javafx.collections.FXCollections;
import javafx.collections.ObservableList;
import javafx.fxml.FXML;
import javafx.fxml.FXMLLoader;
import javafx.scene.Parent;
import javafx.scene.Scene;
import javafx.scene.control.TableColumn;
import javafx.scene.control.TableView;
import javafx.scene.control.cell.PropertyValueFactory;
import javafx.stage.Stage;
public class Start extends Application {
#Override
public void start(Stage stage) throws Exception {
Parent root = FXMLLoader.load(getClass().getResource("mainMrc.fxml"));
Scene scene = new Scene(root);
stage.setTitle("MRC Monitor");
stage.setScene(scene);
stage.show();
}
public static void main(String []args){
launch(args);
}
}
mainMrc.fxml
<?xml version="1.0" encoding="UTF-8"?>
<?import javafx.scene.*?>
<?import javafx.scene.text.*?>
<?import javafx.scene.chart.*?>
<?import javafx.geometry.*?>
<?import javafx.scene.control.*?>
<?import java.lang.*?>
<?import javafx.scene.layout.*?>
<?import javafx.scene.layout.VBox?>
<BorderPane maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" prefHeight="600.0" prefWidth="600.0" xmlns="http://javafx.com/javafx/8" xmlns:fx="http://javafx.com/fxml/1" fx:controller="org.xcellcomm.Controller">
<center>
<VBox prefHeight="200.0" prefWidth="100.0" BorderPane.alignment="CENTER">
<children>
<Label text="Add New Activation :">
<VBox.margin>
<Insets />
</VBox.margin>
</Label>
<HBox prefHeight="100.0" prefWidth="200.0">
<children>
<HBox prefHeight="90.0" prefWidth="200.0">
<children>
<VBox prefHeight="200.0" prefWidth="100.0">
<children>
<Label text="Select Plan Rate :" />
<RadioButton fx:id="plan40Radio" mnemonicParsing="false" text="40 or less Plan" />
<RadioButton fx:id="plan50Radio" mnemonicParsing="false" text="50 Plan" />
<RadioButton fx:id="plan60Radio" mnemonicParsing="false" text="60 Plan" />
<Region prefHeight="16.0" prefWidth="100.0" />
<Button fx:id="buttonAddActivation" mnemonicParsing="false" onAction="#buttonAddActivationPressed" text="Add Activation" />
</children>
</VBox>
</children>
</HBox>
<VBox prefHeight="102.0" prefWidth="163.0">
<children>
<Label text="Added Features :" />
<CheckBox fx:id="checkboxFeaturePhp" layoutX="10.0" layoutY="27.0" mnemonicParsing="false" text="PHP" />
<CheckBox fx:id="checkboxBlockIt" mnemonicParsing="false" text="Block it" />
<CheckBox fx:id="checkboxFeatureValueBundle" mnemonicParsing="false" text="Value Bundle" />
</children>
</VBox>
<VBox prefHeight="200.0" prefWidth="100.0">
<children>
<Label text=" " />
<CheckBox fx:id="checkboxFeatureLookout" mnemonicParsing="false" text="Lookout MS" />
<CheckBox fx:id="checkboxFeatureRhpsody" mnemonicParsing="false" text="Rhapsody" />
<CheckBox fx:id="checkboxFeatureWorldCalling" mnemonicParsing="false" text="World Calling" />
</children>
</VBox>
</children>
</HBox>
<Region prefHeight="23.0" prefWidth="600.0" />
<HBox prefHeight="131.0" prefWidth="580.0">
<children>
<TableView prefHeight="100.0" prefWidth="263.0">
<columns>
<TableColumn prefWidth="109.0" text="Time" />
<TableColumn prefWidth="82.0" text="Plan" />
</columns>
<HBox.margin>
<Insets left="10.0" />
</HBox.margin>
</TableView>
<Region prefHeight="200.0" prefWidth="200.0" HBox.hgrow="ALWAYS" />
<TableView prefHeight="100.0" prefWidth="309.0">
<columns>
<TableColumn prefWidth="147.0" text="Date" />
<TableColumn prefWidth="90.0" text="MRC" />
</columns>
<HBox.margin>
<Insets right="10.0" />
</HBox.margin>
</TableView>
</children>
</HBox>
<Region prefHeight="29.0" prefWidth="580.0" />
<HBox prefHeight="100.0" prefWidth="200.0">
<children>
<VBox prefHeight="150.0" prefWidth="218.0">
<children>
<Label text="Today Activations" />
<TextField fx:id="textfeildTodayActivations" editable="false" maxWidth="100.0" prefHeight="39.0" prefWidth="100.0" promptText="Activations">
<font>
<Font size="18.0" />
</font>
</TextField>
<Label text="Today Goal" />
<TextField fx:id="textfeildTodayGoal" editable="false" maxWidth="100.0" prefHeight="39.0" prefWidth="100.0" promptText="Goal">
<font>
<Font size="18.0" />
</font>
</TextField>
<Label text="Current Process" />
<ProgressBar prefWidth="200.0" progress="0.0" />
</children>
</VBox>
<Region prefHeight="150.0" prefWidth="80.0" HBox.hgrow="ALWAYS" />
<LineChart prefHeight="150.0" prefWidth="281.0">
<xAxis>
<CategoryAxis side="BOTTOM" />
</xAxis>
<yAxis>
<NumberAxis side="LEFT" />
</yAxis>
</LineChart>
</children>
</HBox>
</children>
<BorderPane.margin>
<Insets left="10.0" right="10.0" />
</BorderPane.margin>
</VBox>
</center>
<top>
<MenuBar BorderPane.alignment="CENTER">
<menus>
<Menu mnemonicParsing="false" text="File">
<items>
<MenuItem mnemonicParsing="false" text="Close" />
</items>
</Menu>
<Menu mnemonicParsing="false" text="Edit">
<items>
<MenuItem mnemonicParsing="false" text="Delete" />
</items>
</Menu>
<Menu mnemonicParsing="false" text="Help">
<items>
<MenuItem mnemonicParsing="false" text="About" />
</items>
</Menu>
</menus>
</MenuBar>
</top>
</BorderPane>
Your tableView in the FXML file doesn't have and id, you have <TableView prefHeight="100.0" prefWidth="263.0">and it should have assign an id as you have in yours checkboxs,radiobuttons,etc.

Resources