Why can't I specify NamedArgs and item elements on cellFactory? - javafx

I have the following tableView in fxml
<TableView fx:id="tableView" prefHeight="525.0" prefWidth="814.0">
<columns>
<TableColumn prefWidth="75.0">
<graphic><ToggleButton fx:id="mainToggleButton" maxHeight="1.7976931348623157E308" maxWidth="1.7976931348623157E308" onAction="#onMainToggleButtonAction" text="Start all" /></graphic>
<cellFactory><ToggleButtonTableCellFactory maxHeight="1.7976931348623157E308" maxWidth="1.7976931348623157E308" activatedText="Started" deactivatedText="Stopped"/></cellFactory>
<cellValueFactory><PropertyValueFactory property="state"/></cellValueFactory>
</TableColumn>
<TableColumn prefWidth="75.0" text="Side">
<cellValueFactory><PropertyValueFactory property="side"/></cellValueFactory>
</TableColumn>
<TableColumn prefWidth="75.0" text="Source">
<cellValueFactory><PropertyValueFactory property="sourceContract"/></cellValueFactory>
</TableColumn>
<TableColumn prefWidth="75.0" text="Reference" editable="true">
<cellFactory>
<ChoiceBoxTableCellFactory maxHeight="1.7976931348623157E308" maxWidth="1.7976931348623157E308">
<items>
<FXCollections fx:factory="observableArrayList">
<String fx:value="r01" />
<String fx:value="r02" />
</FXCollections>
</items>
</ChoiceBoxTableCellFactory>
</cellFactory>
<cellValueFactory><PropertyValueFactory property="referenceContract"/></cellValueFactory>
</TableColumn>
<TableColumn prefWidth="75.0" text="Destination">
<cellValueFactory><PropertyValueFactory property="destinationContract"/></cellValueFactory>
</TableColumn>
<TableColumn prefWidth="75.0" text="Margin" editable="true">
<cellFactory><SpinnerTableCellFactory maxHeight="1.7976931348623157E308" maxWidth="1.7976931348623157E308" min="0" max="1" initialValue="0" amountToStepBy="0.025" decimalFormat="0.000"/></cellFactory>
<cellValueFactory><PropertyValueFactory property="margin"/></cellValueFactory>
</TableColumn>
<TableColumn prefWidth="75.0" text="Bot">
<cellValueFactory><PropertyValueFactory property="bot"/></cellValueFactory>
</TableColumn>
<TableColumn prefWidth="75.0" text="Price">
<cellValueFactory><PropertyValueFactory property="price"/></cellValueFactory>
</TableColumn>
<TableColumn prefWidth="75.0" text="Volume">
<cellValueFactory><PropertyValueFactory property="volume"/></cellValueFactory>
</TableColumn>
</columns>
<items>
<FXCollections fx:factory="observableArrayList">
<GridRowModel state="false" side="BID" sourceContract="s01" referenceContract="r01" destinationContract="d01" margin="0" bot="MinMax" price="15.125" volume="0" />
<GridRowModel state="false" side="ASK" sourceContract="s02" referenceContract="r01" destinationContract="d02" margin="0" bot="MinMax" price="15.125" volume="0" />
</FXCollections>
</items>
</TableView>
The ChoiceBoxTableCellFactory has a constructor which takes both named arguments from the fxml and a setter for the items element.
public class ChoiceBoxTableCellFactory<S, T> implements Callback<TableColumn<S, String>, TableCell<S, String>> {
private ObservableList<String> items;
private double maxHeight;
private double maxWidth;
public ChoiceBoxTableCellFactory() {
}
public ChoiceBoxTableCellFactory(
#NamedArg("maxHeight") double maxHeight,
#NamedArg("maxWidth") double maxWidth) {
this.maxHeight = maxHeight;
this.maxWidth = maxWidth;
}
#Override
public TableCell<S, String> call(TableColumn<S, String> param) {
return new TableCell<S, String>() {
ChoiceBox<String> choiceBox = new ChoiceBox<>(getItems());
{
choiceBox.setMaxHeight(maxHeight);
choiceBox.setMaxWidth(maxWidth);
choiceBox.valueProperty().addListener((obs, oldValue, newValue) -> {
ObservableValue<String> value = getTableColumn().getCellObservableValue(getIndex());
if (value instanceof WritableValue) {
((WritableValue<String>) value).setValue(newValue);
}
});
}
#Override
protected void updateItem(String item, boolean empty) {
super.updateItem(item, empty);
if (empty) {
setText(null);
setGraphic(null);
} else {
if (isEditing()) {
setText(null);
setGraphic(null);
} else {
choiceBox.setValue(item);
setText(null);
setGraphic(choiceBox);
}
}
}
};
}
public ObservableList<String> getItems() {
return items;
}
public void setItems(ObservableList<String> items) {
this.items = items;
}
}
But that throws this exception
Caused by: java.lang.IllegalArgumentException: Unable to coerce [[r01, r02]] to interface javafx.collections.ObservableList.
at com.sun.javafx.fxml.BeanAdapter.coerce(BeanAdapter.java:496)
at com.sun.javafx.fxml.builder.ProxyBuilder$Setter.invoke(ProxyBuilder.java:533)
at com.sun.javafx.fxml.builder.ProxyBuilder.createObjectFromDefaultConstructor(ProxyBuilder.java:338)
... 144 more
When I remove the maxHeight and maxWidth attributes the items field is set correctly through the setter. With these attributes the items value is wrapped in an additional array. How can I achieve the desired result?

That looks like it should work. I tried a simpler test and the following workarounds seemed to work there:
If you don't need the setItems() method anywhere else in your code, remove it and use the read only list properties approach. I.e. remove the setItems(...) method entirely, and in the FXML do
<ChoiceBoxTableCellFactory maxHeight="1.7976931348623157E308" maxWidth="1.7976931348623157E308">
<items>
<String fx:value="r01" />
<String fx:value="r02" />
</items>
</ChoiceBoxTableCellFactory>
The other way around seems to be to use an <fx:define> block to define the items, and initialize it using an attribute:
<fx:define>
<FXCollections fx:factory="observableArrayList" fx:id="items">
<String fx:value="r01"/>
<String fx:value="r02"/>
</FXCollections>
<fx:define>
<ChoiceBoxTableCellFactory maxHeight="1.7976931348623157E308" maxWidth="1.7976931348623157E308"
items="$items" />

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

How to add data in table-view using only fxml (without any java code)?

I want to add test data in table-view using only fxml. I don't know how to!
Just like this.
e.g i insert data in combobox using fxml. like this.
It is generated using only fxml. e.g.
<ComboBox prefHeight="25.0" prefWidth="193.0" promptText="Select your best language" visibleRowCount="5">
<items>
<FXCollections fx:factory="observableArrayList">
<String fx:value="java" />
<String fx:value="javafx" />
<String fx:value="css" />
<String fx:value="fxml" />
<String fx:value="c++" />
</FXCollections>
</items>
</ComboBox>
Also i add list view using fxml. like this.
using fxml:
<ListView maxHeight="-Infinity" maxWidth="-Infinity" prefHeight="200.0" prefWidth="200.0" >
<items>
<FXCollections fx:factory="observableArrayList">
<String fx:value="java" />
<String fx:value="javafx" />
<String fx:value="css" />
<String fx:value="fxml" />
<String fx:value="c++" />
<String fx:value="visual basic" />
<String fx:value="groovy" />
<String fx:value="coltion" />
</FXCollections>
</items>
</ListView>
But how to add data in table-view. using only fxml. I want this so that i can view real time in scene-builder preview.
Here is an example. Code from here.
Key code
<TableView fx:id="tableView" GridPane.columnIndex="0" GridPane.rowIndex="1">
<columns>
<TableColumn text="First Name">
<cellValueFactory>
<PropertyValueFactory property="firstName" />
</cellValueFactory>
</TableColumn>
<TableColumn text="Last Name">
<cellValueFactory>
<PropertyValueFactory property="lastName" />
</cellValueFactory>
</TableColumn>
<TableColumn text="Email Address">
<cellValueFactory>
<PropertyValueFactory property="email" />
</cellValueFactory>
</TableColumn>
</columns>
<items>
<FXCollections fx:factory="observableArrayList">
<Person firstName="Jacob" lastName="Smith"
email="jacob.smith#example.com"/>
<Person firstName="Isabella" lastName="Johnson"
email="isabella.johnson#example.com"/>
<Person firstName="Ethan" lastName="Williams"
email="ethan.williams#example.com"/>
<Person firstName="Emma" lastName="Jones"
email="emma.jones#example.com"/>
<Person firstName="Michael" lastName="Brown"
email="michael.brown#example.com"/>
</FXCollections>
</items>
</TableView>
FULL CODE:
Main
import javafx.application.Application;
import javafx.fxml.FXMLLoader;
import javafx.scene.Parent;
import javafx.scene.Scene;
import javafx.stage.Stage;
/**
*
* #author blj0011
*/
public class JavaFXApplication312 extends Application
{
#Override
public void start(Stage stage) throws Exception
{
Parent root = FXMLLoader.load(getClass().getResource("FXMLDocument.fxml"));
Scene scene = new Scene(root);
stage.setScene(scene);
stage.show();
}
/**
* #param args the command line arguments
*/
public static void main(String[] args)
{
launch(args);
}
}
FXML
<?xml version="1.0" encoding="UTF-8"?>
<?import java.lang.*?>
<?import java.util.*?>
<?import javafx.scene.*?>
<?import javafx.scene.control.*?>
<?import javafx.scene.layout.*?>
<?import javafx.scene.control.cell.*?>
<?import javafx.collections.*?>
<?import javafxapplication312.Person?>
<AnchorPane id="AnchorPane" prefHeight="200" prefWidth="320" xmlns:fx="http://javafx.com/fxml/1" fx:controller="javafxapplication312.FXMLDocumentController">
<children>
<TableView fx:id="tableView" GridPane.columnIndex="0" GridPane.rowIndex="1">
<columns>
<TableColumn text="First Name">
<cellValueFactory>
<PropertyValueFactory property="firstName" />
</cellValueFactory>
</TableColumn>
<TableColumn text="Last Name">
<cellValueFactory>
<PropertyValueFactory property="lastName" />
</cellValueFactory>
</TableColumn>
<TableColumn text="Email Address">
<cellValueFactory>
<PropertyValueFactory property="email" />
</cellValueFactory>
</TableColumn>
</columns>
<items>
<FXCollections fx:factory="observableArrayList">
<Person firstName="Jacob" lastName="Smith"
email="jacob.smith#example.com"/>
<Person firstName="Isabella" lastName="Johnson"
email="isabella.johnson#example.com"/>
<Person firstName="Ethan" lastName="Williams"
email="ethan.williams#example.com"/>
<Person firstName="Emma" lastName="Jones"
email="emma.jones#example.com"/>
<Person firstName="Michael" lastName="Brown"
email="michael.brown#example.com"/>
</FXCollections>
</items>
</TableView>
</children>
</AnchorPane>
Controller
import java.net.URL;
import java.util.ResourceBundle;
import javafx.fxml.Initializable;
/**
*
* #author blj0011
*/
public class FXMLDocumentController implements Initializable
{
#Override
public void initialize(URL url, ResourceBundle rb)
{
// TODO
}
}
Person
import javafx.beans.property.SimpleStringProperty;
public class Person
{
private final SimpleStringProperty firstName = new SimpleStringProperty("");
private final SimpleStringProperty lastName = new SimpleStringProperty("");
private final SimpleStringProperty email = new SimpleStringProperty("");
public Person()
{
this("", "", "");
}
public Person(String firstName, String lastName, String email)
{
setFirstName(firstName);
setLastName(lastName);
setEmail(email);
}
public String getFirstName()
{
return firstName.get();
}
public void setFirstName(String fName)
{
firstName.set(fName);
}
public String getLastName()
{
return lastName.get();
}
public void setLastName(String fName)
{
lastName.set(fName);
}
public String getEmail()
{
return email.get();
}
public void setEmail(String fName)
{
email.set(fName);
}
}

how to declare date value property for tableview

I need to pass the date property to the setCellValueFactory , this is the code for the seters and geters of my Persona class, what is the correct method to do that, i think i having an issue whit the correct declaration, so i need a real direction here, i need to declare some date in the java.sql.date class, do some reference? any idea?. please a little help here.
package application;
import java.time.LocalDate;
import javafx.beans.property.IntegerProperty;
import javafx.beans.property.ObjectProperty;
import javafx.beans.property.SimpleIntegerProperty;
import javafx.beans.property.SimpleObjectProperty;
import javafx.beans.property.SimpleStringProperty;
import javafx.beans.property.StringProperty;
public class Persona {
private StringProperty nombres;
private StringProperty apellidos;
private IntegerProperty id_cliente;
private ObjectProperty <LocalDate>fechacliente;
public Persona ( String nombres, String apellidos, Integer id_cliente, Object fechacliente) {
this.nombres= new SimpleStringProperty (nombres);
this.apellidos= new SimpleStringProperty ( apellidos);
this.id_cliente=new SimpleIntegerProperty (id_cliente);
this.fechacliente= new SimpleObjectProperty<LocalDate>();
}
public Object getFecha() {
return fechacliente.get();
}
public void setFecha(Object fechacliente) {
this.fechacliente=new SimpleObjectProperty<>();
}
public String getNombres() {
return nombres.get();
}
public void setNombres(String nombres) {
this.nombres=new SimpleStringProperty (nombres);
}
public String getApellidos() {
return apellidos.get();
}
public void setApellidos(String apellidos) {
this.apellidos=new SimpleStringProperty ( apellidos);
}
public Integer getId_cliente() {
return id_cliente.get();
}
public void setid_cliente(Integer id_cliente) {
this.id_cliente=new SimpleIntegerProperty (id_cliente);
}
}
Some of Controller here that set the values to the tableview
public void initialize(URL arg0, ResourceBundle arg1) {
clienteid.setCellValueFactory(new PropertyValueFactory <Persona, Integer>("id_cliente"));
nombrescol.setCellValueFactory(new PropertyValueFactory <Persona, String>("nombres"));
apellidoscol.setCellValueFactory(new PropertyValueFactory <Persona, String>("apellidos"));
fechacli.setCellValueFactory(new PropertyValueFactory <Persona, LocalDate>("fechacliente"));
seleccionaregistros();
seleccionanombre();
seleccionapellido();
}
this is the method i am using to retrieve the data in the tableview but the date does not show
public void seleccionaregistros() {
ObservableList <Persona> data =FXCollections.observableArrayList();
Connection conn=null;{
try {
conn = DriverManager.getConnection("jdbc:sqlserver://localhost:1433;databaseName=prueba", "sa", "milkas87");
Statement mostrar=conn.createStatement();
ResultSet rs;
rs= mostrar.executeQuery("select * from cliente");
while ( rs.next() )
{
data.add(new Persona(
rs.getString("nombre"),
rs.getString("apellido"),
rs.getInt("id"),
rs.getDate(4)
));
tablacliente.setItems(data);
}
} catch (SQLException e) {
e.printStackTrace();
}
}
}
The date does not show in the tableview , i need to format the date to pass that value in the tableview i think. please some orientation here be helpful.
this is my FXML Code
<?xml version="1.0" encoding="UTF-8"?>
<?import javafx.scene.control.*?>
<?import java.lang.*?>
<?import javafx.scene.layout.*?>
<?import javafx.scene.layout.AnchorPane?>
<AnchorPane prefHeight="497.0" prefWidth="943.0" xmlns="http://javafx.com/javafx/8" xmlns:fx="http://javafx.com/fxml/1" fx:controller="application.ConexionController">
<children>
<Pane layoutY="-3.0" prefHeight="605.0" prefWidth="1084.0">
<children>
<Button fx:id="btn" layoutX="145.0" layoutY="109.0" mnemonicParsing="false" onAction="#cargarconexion" prefHeight="46.0" prefWidth="117.0" text="Prueba Conexion" />
<Button fx:id="mtn" layoutX="15.0" layoutY="183.0" mnemonicParsing="false" onAction="#cargarregistro" prefHeight="46.0" prefWidth="117.0" text="Inserta Registro" />
<Label layoutX="14.0" layoutY="279.0" prefHeight="17.0" prefWidth="105.0" text="NOMBRES" />
<Label layoutX="15.0" layoutY="327.0" prefHeight="17.0" prefWidth="79.0" text="APELLIDOS" />
<TextField fx:id="nm" layoutX="159.0" layoutY="275.0" prefHeight="25.0" prefWidth="149.0" />
<TextField fx:id="ap" layoutX="159.0" layoutY="323.0" />
<Button fx:id="lmp" layoutX="159.0" layoutY="484.0" mnemonicParsing="false" onAction="#borrarcasillatexto" prefHeight="25.0" prefWidth="150.0" text="Limpiar Texto" />
<TableView fx:id="tablacliente" layoutX="355.0" layoutY="15.0" prefHeight="383.0" prefWidth="696.0">
<columns>
<TableColumn fx:id="clienteid" prefWidth="159.0" text="ID" />
<TableColumn fx:id="nombrescol" prefWidth="159.0" text="NOMBRES" />
<TableColumn fx:id="apellidoscol" minWidth="0.0" prefWidth="169.0" text="APELLIDOS" />
<TableColumn fx:id="fechacli" prefWidth="235.0" text="FECHA DE NACIMIENTO" />
</columns>
</TableView>
<Button fx:id="mts" layoutX="15.0" layoutY="109.0" mnemonicParsing="false" onAction="#mostrartodo" prefHeight="46.0" prefWidth="117.0" text="Mostrar" />
<TextField fx:id="bq" layoutX="554.0" layoutY="417.0" prefHeight="25.0" prefWidth="149.0" />
<Button fx:id="bqd" layoutX="758.0" layoutY="417.0" mnemonicParsing="false" onAction="#buscanm" prefHeight="25.0" prefWidth="155.0" text="BUSCAR NOMBRE" />
<Button fx:id="bqape" layoutX="758.0" layoutY="458.0" mnemonicParsing="false" onAction="#buscaape" prefHeight="25.0" prefWidth="155.0" text="BUSCAR POR APELLIDO" />
<TextField fx:id="bqa" layoutX="554.0" layoutY="458.0" />
<ComboBox layoutX="159.0" layoutY="430.0" prefWidth="150.0" />
<Label layoutX="15.0" layoutY="434.0" prefHeight="17.0" prefWidth="55.0" text="GENERO" />
<MenuBar fx:id="menucombo" layoutY="3.0">
<menus>
<Menu mnemonicParsing="false" text="Agregar">
<items>
<MenuItem mnemonicParsing="false" onAction="#inicializacombo" text="Datos Cliente" />
</items>
</Menu>
</menus>
</MenuBar>
<Button fx:id="botonborrar" layoutX="758.0" layoutY="507.0" mnemonicParsing="false" onAction="#borraregistroid" prefHeight="25.0" prefWidth="155.0" text="BORRAR REGISTRO" />
<TextField fx:id="borrar" layoutX="554.0" layoutY="507.0" />
<DatePicker fx:id="mifecha" layoutX="158.0" layoutY="371.0" prefHeight="25.0" prefWidth="150.0" />
<Label layoutX="15.0" layoutY="375.0" prefHeight="17.0" prefWidth="150.0" text="FECHA DE NACIMIENTO" />
</children>
</Pane>
</children>
</AnchorPane>
You're using JavaFX properties incorrectly. A property for a JavaFX Bean needs a getter, setter (if writable), and a property getter. Also, the setter should not be creating a new property each time; it should be setting the value of the existing property.
To simplify your example, if we have a Person with a single property, name, it would look like this:
public class Person {
private final StringProperty name = new SimpleStringProperty(this, "name");
public Person(String name) {
setName(name);
}
public final void setName(String name) { // setter
this.name.set(name);
}
public final String getName() { // getter
return name.get();
}
public final StringProperty nameProperty() { // property getter
return name;
}
}
Note: You can still initialize the properties in the constructor, instead of at the field declaration, if you want.
To use the name property in a TableView or TreeTableView you would simply return it in the cellValueFactory. Example using a TableView:
TableView<Person> table = new TableView<>();
TableColumn<Person, String> nameCol = new TableColumn<>("Name");
nameCol.setCellValueFactory(features -> features.getValue().nameProperty());
table.getColumns().add(nameCol);
Another issue with your code is that you're using a raw ObjectProperty. Don't use raw types. Instead, you should be using an ObjectProperty<Date> where Date is java.sql.Date. For example:
public class Person {
private final ObjectProperty<Date> clientDate = new SimpleObjectProperty<>(this, "clientDate");
public final void setClientDate(Date clientDate) {
this.clientDate.set(clientDate);
}
public final Date getClientDate() {
return clientDate.get();
}
public final ObjectProperty<Date> clientDateProperty() {
return clientDate;
}
}
Note: It'd probably be better to use one of the java.time classes (e.g. LocalDate, OffsetDateTime, etc...).
And again, to add it to a TableView it'd look like:
TableView<Person> table = new TableView<>();
TableColumn<Person, Date> clientDateCol= new TableColumn<>("Client Date");
clientDateCol.setCellValueFactory(features -> features.getValue().clientDateProperty());
table.getColumns().add(clientDateCol);

While adding pagination in javafx ,pagination call back function is not getting called

FXML
<?xml version="1.0" encoding="UTF-8"?>
<?import javafx.scene.control.Button?>
<?import javafx.scene.control.ComboBox?>
<?import javafx.scene.control.Label?>
<?import javafx.scene.control.Pagination?>
<?import javafx.scene.control.TableColumn?>
<?import javafx.scene.control.TableView?>
<?import javafx.scene.control.TextField?>
<?import javafx.scene.layout.Pane?>
<Pane xmlns="http://javafx.com/javafx/8.0.171" xmlns:fx="http://javafx.com/fxml/1" fx:controller="com.medplus.posoffline.gui.ReturnsPickListController">
<children>
<Pane prefHeight="600.0" prefWidth="800.0">
<children>
<Label layoutX="5.0" layoutY="15.0" text="RequestId" />
<TextField fx:id="requestId" layoutX="75.0" layoutY="15.0" prefWidth="140.0" />
<Label layoutX="245.0" layoutY="15.0" text="Status" />
<ComboBox fx:id="returnStatusComb" layoutX="295.0" layoutY="15.0" prefWidth="140.0">
</ComboBox>
<Label layoutX="470.0" layoutY="15.0" text="Type" />
<ComboBox fx:id="returnTypeComb" layoutX="510.0" layoutY="15.0" prefWidth="140.0">
</ComboBox>
<Button layoutX="598.0" layoutY="60.0" mnemonicParsing="false" onAction="#searcReturnDetailsfroPickList" text="Search" />
<TableView fx:id="tableView" layoutY="95.0" prefHeight="450.0" prefWidth="800.0">
<columns>
<TableColumn fx:id="requestIdsBtn" minWidth="200.0" prefWidth="75.0" text="RequestID" />
<TableColumn fx:id="status" minWidth="200.0" prefWidth="75.0" text="Status" />
<TableColumn fx:id="type" minWidth="200.0" prefWidth="75.0" text="Type" />
<TableColumn fx:id="dateCreated" minWidth="200.0" prefWidth="75.0" text="DateCreated" />
</columns>
</TableView>
<Pagination fx:id="returnsScreenpagination" layoutX="529.0" layoutY="394.0" prefHeight="200.0" prefWidth="200.0" />
</children>
</Pane>
</children>
</Pane>
Controller
#Override
public void initialize(URL location, ResourceBundle resources) {
setCombsValues();
ReturnRequestSearchCriteria returnRequestSearchCriteria = new ReturnRequestSearchCriteria();
returnRequestSearchCriteria.setDetailsRequired(false);
try {
returnRequests = transferUtility.getStoreReturnDetails(returnRequestSearchCriteria);
} catch (TransferException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
returnsScreenpagination = new Pagination(5,0);
returnsScreenpagination.setPageFactory((Integer pageIndex) -> {
System.out.println(pageIndex);
if (UtilValidate.isEmpty(returnRequests)) {
return null;
} else {
return createPage(pageIndex,returnRequests);
}
});
public TableView<ReturnRequest> createPage(int pageIndex,List<ReturnRequest> returnRequests) {
status.setCellValueFactory(new PropertyValueFactory<ReturnRequest, ReturnRequestType>("status"));
type.setCellValueFactory(new PropertyValueFactory<ReturnRequest, ReturnRequestStatus>("type"));
dateCreated.setCellValueFactory(new PropertyValueFactory<ReturnRequest, Date>("dateCreated"));
requestIdsBtn.setCellValueFactory(new PropertyValueFactory<ReturnRequest, String>("requestId"));
requestIdsBtn.setSortable(false);
dateCreated.setCellFactory(column -> {
TableCell<ReturnRequest, Date> cell = new TableCell<ReturnRequest, Date>() {
private SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
#Override
protected void updateItem(Date item, boolean empty) {
super.updateItem(item, empty);
if(empty) {
setText(null);
}
else {
this.setText(format.format(item));
}
}
};
return cell;
});
requestIdsBtn.setCellValueFactory(
new Callback<TableColumn.CellDataFeatures<ReturnRequest, String>,
ObservableValue<String>>() {
#Override
public ObservableValue<String> call(CellDataFeatures<ReturnRequest, String> param) {
ObservableValue<String> obsLong = new SimpleLongProperty(param.getValue().getRequestId()).asString();
return obsLong;
}
});
requestIdsBtn.setCellFactory(
new Callback<TableColumn<ReturnRequest, String>, TableCell<ReturnRequest, String>>() {
#Override
public TableCell<ReturnRequest, String> call(TableColumn<ReturnRequest, String> p) {
return new ButtonCell();
}
});
List<ReturnRequest> sublist = returnRequests.subList(0, 5);
System.out.println(sublist);
observableProductList.addAll(sublist);
tableView.setItems( observableProductList);
return tableView;
}
I Am not able to get any data in the TableView. In call back method ...print which I kept, it's not getting printed.
Please help in getting data in a table according to my pagination.
Is there any other way to display pagination in JavaFX including FXML file
when pagination call back method is called?
Thanks in advance

JavaFX why TableView don't load data

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

Resources