javafx getselecteditem returns unexpected output [duplicate] - javafx

This question already has answers here:
How do I print my Java object without getting "SomeType#2f92e0f4"?
(13 answers)
Closed 6 years ago.
I am trying to do is get the data from the current selected row on a button click, and return that. However what it returns now is something that seems to be in the format of packagename+ classname+ randomnumbers and letters.
simple.UserDetails#3f59ec1e
simple.UserDetails#210337a8
Random numbers and letters do change when another row is selected. I tried to use thread as example. Getting selected item from a JavaFX TableView. I would like an answer on how I can achieve the result that I desire. And, if possible be able to save the data in variables too.
Method I use:
#FXML
public void getRow() {
UserDetails row = tableview.getSelectionModel().getSelectedItem();
System.out.println(row);
}
The controller class.
package simple;
import java.net.URL;
import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ResourceBundle;
import javafx.collections.FXCollections;
import javafx.collections.ObservableList;
import javafx.fxml.FXML;
import javafx.fxml.Initializable;
import javafx.scene.control.Button;
import javafx.scene.control.TableColumn;
import javafx.scene.control.TableView;
import javafx.scene.control.cell.PropertyValueFactory;
/**
*
* #author admin
*/
public class FXMLUserController implements Initializable {
#FXML
private TableView<UserDetails> tableview;
#FXML
private TableColumn<UserDetails, String> columnId;
#FXML
private TableColumn<UserDetails, String> columnType;
#FXML
private TableColumn<UserDetails, String> columnKleur;
#FXML
private TableColumn<UserDetails, String> columnLuchthaven;
#FXML
private TableColumn<UserDetails, String> columnKenmerken;
#FXML
private TableColumn<UserDetails, String> columnStatus;
#FXML
private TableColumn<UserDetails, String> columnDatum;
#FXML
private Button btnLoad;
//declare observable list for database data
private ObservableList<UserDetails> data;
private DbConnection dc;
#FXML
private Button editRow;
#Override
public void initialize(URL url, ResourceBundle rb) {
dc = new DbConnection();
loadDataFromDatabase();
}
#FXML
public void loadDataFromDatabase() {
try {
Connection conn = dc.Connect();
data = FXCollections.observableArrayList();
// Execute query and store result in a resultset
ResultSet rs = conn.createStatement().executeQuery("SELECT * FROM gevonden_bagage");
while (rs.next()) {
//get strings
data.add(new UserDetails(rs.getString(1), rs.getString(2), rs.getString(3), rs.getString(4), rs.getString(5),
rs.getString(6), rs.getString(7)));
}
} catch (SQLException ex) {
System.err.println("Error" + ex);
}
//Set cell values to tableview.
tableview.setEditable(true);
columnId.setCellValueFactory(new PropertyValueFactory<>("id"));
columnType.setCellValueFactory(new PropertyValueFactory<>("type"));
columnKleur.setCellValueFactory(new PropertyValueFactory<>("kleur"));
columnLuchthaven.setCellValueFactory(new PropertyValueFactory<>("luchthaven"));
columnKenmerken.setCellValueFactory(new PropertyValueFactory<>("kenmerken"));
columnStatus.setCellValueFactory(new PropertyValueFactory<>("status"));
columnDatum.setCellValueFactory(new PropertyValueFactory<>("datum"));
tableview.setItems(null);
tableview.setItems(data);
}
#FXML
public void getRow() {
UserDetails row = tableview.getSelectionModel().getSelectedItem();
System.out.println(row);
}
}
Model class
package simple;
import javafx.beans.property.SimpleStringProperty;
import javafx.beans.property.StringProperty;
/**
*
* #author admin
*/
public class UserDetails {
private final StringProperty id;
private final StringProperty type;
private final StringProperty kleur;
private final StringProperty luchthaven;
private final StringProperty kenmerken;
private final StringProperty status;
private final StringProperty datum;
//Default constructor
public UserDetails(String id, String type, String kleur, String luchthaven, String kenmerken, String status, String datum) {
this.id = new SimpleStringProperty(id);
this.type = new SimpleStringProperty(type);
this.kleur = new SimpleStringProperty(kleur);
this.luchthaven = new SimpleStringProperty(luchthaven);
this.kenmerken = new SimpleStringProperty(kenmerken);
this.status = new SimpleStringProperty(status);
this.datum = new SimpleStringProperty(datum);
}
//getters
public String getId() {
return id.get();
}
public String getType() {
return type.get();
}
public String getKleur() {
return kleur.get();
}
public String getLuchthaven() {
return luchthaven.get();
}
public String getKenmerken() {
return kenmerken.get();
}
public String getStatus() {
return status.get();
}
public String getDatum() {
return datum.get();
}
//setters
public void setId(String value) {
id.set(value);
}
public void setType(String value) {
type.set(value);
}
public void setKleur(String value) {
kleur.set(value);
}
public void setLuchthaven(String value) {
luchthaven.set(value);
}
public void setKenmerken(String value) {
kenmerken.set(value);
}
public void setStatus(String value) {
status.set(value);
}
public void setDatum(String value) {
datum.set(value);
}
//property values
public StringProperty idProperty() {
return id;
}
public StringProperty typeProperty() {
return type;
}
public StringProperty kleurProperty() {
return kleur;
}
public StringProperty luchthavenProperty() {
return luchthaven;
}
public StringProperty kenmerkenProperty() {
return kenmerken;
}
public StringProperty statusProperty() {
return status;
}
public StringProperty datumProperty() {
return datum;
}
}

You need to say something like row.someMethodorVariableInUserDetails
What ever you are trying to return is in your UserDetails class
Look at this example from here
Person person = taview.getSelectionModel().getSelectedItem();
System.out.println(person.getName());
In this example they have to say person.somemethod(). In this case person.getName();

Related

Can't Load all the data from bin file into text View. My program just show the latest value in tableView. Can't apply the loop properly

In this code, I'm trying to read data from the bin file and set it in the table view column. But I can't set the loop properly in loadTableFromFileButtonOnClick.It is only showing the latest value from the bin file. But I want to load all the binding data from the bin file Here is my controller class code.
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.net.URL;
import java.time.LocalDate;
import java.util.ResourceBundle;
import javafx.event.ActionEvent;
import javafx.fxml.FXML;
import javafx.fxml.Initializable;
import javafx.scene.control.Button;
import javafx.scene.control.DatePicker;
import javafx.scene.control.TableColumn;
import javafx.scene.control.TableView;
import javafx.scene.control.TextArea;
import javafx.scene.control.TextField;
import javafx.scene.control.cell.PropertyValueFactory;
import javafx.scene.input.MouseEvent;
public class FXMLMainSceneController implements Initializable {
#FXML private TextField idTxt;
#FXML private TextField nameTxt;
#FXML private TextField deptTxt;
#FXML private TextField cgpaTxt;
#FXML private DatePicker birthdayDatePicker;
#FXML private TableView<Student> tableView;
#FXML private TableColumn<Student, String> idColumn;
#FXML private TableColumn<Student, String> nameColumn;
#FXML private TableColumn<Student, LocalDate> birthdayColumn;
#FXML private TableColumn<Student, String> deptColumn;
#FXML private TableColumn<Student, String> cgpaColumn;
#Override
public void initialize(URL url, ResourceBundle rb) {
idColumn.setCellValueFactory(new PropertyValueFactory<Student,String>("id"));
nameColumn.setCellValueFactory(new PropertyValueFactory<Student,String>("name"));
birthdayColumn.setCellValueFactory(new PropertyValueFactory<Student,LocalDate>("birthday"));
deptColumn.setCellValueFactory(new PropertyValueFactory<Student,String>("dept"));
cgpaColumn.setCellValueFactory(new PropertyValueFactory<Student,String>("cgpa"));
}
#FXML
private void saveToFileButtonOnClick(ActionEvent event) {
Student stud = new Student(
Integer.parseInt(idTxt.getText()),
nameTxt.getText(),
birthdayDatePicker.getValue(),
deptTxt.getText(),
Float.parseFloat(cgpaTxt.getText())
);
idTxt.setText(null); nameTxt.setText(null); cgpaTxt.setText(null); deptTxt.setText(null);
stud.display();
try {
ObjectOutputStream oos = new ObjectOutputStream(new FileOutputStream("Stud.bin"));
oos.writeObject(stud);
oos.close();
} catch (Exception ex) {
ex.printStackTrace();
}
}
#FXML
private void loadTableFromFileButtonOnClick(ActionEvent event) {
ObjectInputStream ois=null;
try {
Student s;
//There will be a loop for set up all the data ,i tried bt can't apply it properly
ois = new ObjectInputStream(new FileInputStream("Stud.bin"));
s = (Student) ois.readObject();
s.display();
tableView.getItems().add(s);
} catch (Exception ex) {
try {
if(ois!=null)
ois.close();
}
catch (IOException e) {
e.printStackTrace();
}
ex.printStackTrace();
}
}
#FXML
private void idTxtOnMouseClick(MouseEvent event) {
idTxt.setText(null);
}
#FXML
private void nameTxtOnMouseClick(MouseEvent event) {
nameTxt.setText(null);
}
#FXML
private void cgpaTxtOnMouseClick(MouseEvent event) {
cgpaTxt.setText(null);
}
#FXML
private void deptTxtOnMouseClick(MouseEvent event) {
deptTxt.setText(null);
}
}
Here is my subclass
import java.io.Serializable;
import java.time.LocalDate;
public class Student extends Person implements Serializable{
int id;
String dept;
float cgpa;
public Student(int id, String name, LocalDate birthday, String dept, float cgpa) {
super(name, birthday);
this.id = id;
this.dept = dept;
this.cgpa = cgpa;
}
public void setId(int id) {
this.id = id;
}
public void setDept(String dept) {
this.dept = dept;
}
public void setCgpa(float cgpa) {
this.cgpa = cgpa;
}
public int getId() {
return id;
}
public String getDept() {
return dept;
}
public float getCgpa() {
return cgpa;
}
#Override
public String toString(){
return "Id="+id+", Name="+name+", DoB="+birthday+", Dept="+dept+", Cgpa="+cgpa;
}
public void display(){
System.out.println("Id="+id+", Name="+name+", DoB="+birthday+", Dept="+dept+", Cgpa="+cgpa);
}
}
here is my superclass
import java.io.Serializable;
import java.time.LocalDate;
import javafx.beans.property.SimpleStringProperty;
public class Person implements Serializable{
protected String name;
protected LocalDate birthday;
public Person(String name, LocalDate birthday) {
this.name = name;
this.birthday = birthday;
}
public void setName(String name) {
this.name = name;
}
public void setBirthday(LocalDate birthday) {
this.birthday = birthday;
}
public String getName() {
//return firstName;
return name;
}
public LocalDate getBirthday() {
return birthday;
}
}

How to dynamically add data in tableview?

This are the colid specify in fxml file, I don't know the way. If I press the add button inputted data are not showing in the table view. Some blank row has been added. I want to add data in tableview from user.
#FXML
private TableColumn<AddItemDetails, String> colofiice_name;
#FXML
private TableColumn<AddItemDetails, String> colref_name;
#FXML
private TableColumn<AddItemDetails, String> colch_item_name;
#FXML
private TableColumn<AddItemDetails, String> colch_item_code;
#FXML
private TableColumn<AddItemDetails, String> colch_unit;
#FXML
private TableColumn<AddItemDetails, String> colch_qty;
#FXML
private TableColumn<AddItemDetails, String> colch_rec_by;
#FXML
private TableColumn<AddItemDetails, String> colch_desig;
#FXML
private TableColumn<AddItemDetails, String> colch_addr;
#FXML
private TableColumn<AddItemDetails, String> colch_remark;
#FXML
private TableColumn<AddItemDetails, String> colch_no;
#FXML
private TableColumn<AddItemDetails, String> colch_action;
private JFXCheckBox CB;
I write this code in controller
public void AddTableView(ActionEvent event)throws SQLException{
AddItemDetails additem = new AddItemDetails();
additem.setOfficeName(select_office.getValue());
additem.setRefNo(challan_select_item.getValue());
additem.setItemName(txt_ref_no.getText());
additem.setItemCode(txt_item_code.getText());
additem.setItemUnit(txt_unit.getText());
additem.setItemQty(txt_qty.getText());
additem.setReceiveBY(txt_rec_by.getText());
additem.setDesignation(txt_desig.getText());
additem.setChNo(txt_chllan.getText());
additem.setAddress(txt_addr.getText());
additem.setRemarks(txt_remark.getText());
additem.setAction(CB);
tableview2.getItems().addAll(additem);
}catch(Exception e){
e.printStackTrace();
}
this my AddItemDetails Class
package inventory_system_app;
import com.jfoenix.controls.JFXCheckBox;
import com.jfoenix.controls.JFXComboBox;
import javafx.beans.property.SimpleStringProperty;
import javafx.beans.property.StringProperty;
public class AddItemDetails {
private String office_name;
private String ref_no;
private String I_name;
private String I_code;
private String I_unit;
private String I_qty;
private String rec_by;
private String desig;
private String ch_no;
private String address;
private String ch_remarks;
private JFXCheckBox Action;
public AddItemDetails(String office_name,String ref_no,String I_name,String
I_code,String I_unit, String I_qty,String rec_by,String desig,String
ch_no,String address, String ch_remarks, String value){
this.office_name = office_name;
this.ref_no = ref_no;
this.I_name = I_name;
this.I_code = I_code;
this.I_unit = I_unit;
this.I_qty = I_qty;
this.rec_by = rec_by;
this.desig = desig;
this.ch_no = ch_no;
this.address = address;
this.ch_remarks = ch_remarks;
this.Action = new JFXCheckBox();
}
AddItemDetails() {
}
public String getOfficeName(){
return office_name;
}
public String getRefNo(){
return ref_no;
}
public String getItemName(){
return I_name;
}
public String getItemCode(){
return I_code;
}
public String getItemUnit(){
return I_unit;
}
public String getItemQty(){
return I_qty;
}
public String getReceiveBY(){
return rec_by;
}
public String getDesignation(){
return desig;
}
public String getChNo(){
return ch_no;
}
public String getAddress(){
return address;
}
public String getRemarks(){
return ch_remarks;
}
public JFXCheckBox getAction() {
return Action;
}
public void setOfficeName(String value){
this.office_name= value;
}
public void setRefNo(String value){
this.ref_no=value;
}
public void setItemName(String value){
this.I_name=value;
}
public void setItemCode(String value){
this.I_code=value;
}
public void setItemUnit(String value){
this.I_unit=value;
}
public void setItemQty(String value){
this.I_qty=value;
}
public void setReceiveBY(String value){
this.rec_by=value;
}
public void setDesignation(String value){
this.desig=value;
}
public void setChNo(String value){
this.ch_no=value;
}
public void setAddress(String value){
this.address=value;
}
public void setRemarks(String value){
this.ch_remarks=value;
}
public void setAction(JFXCheckBox Action) {
this.Action = Action;
}
}
Steps to make your code working:
1.
In the AddItemDetails replace every String field which you want to show in the table with StringPropertyes like:
public class AddItemDetails {
private StringProperty office_name;
private StringProperty ref_no;
private StringProperty I_name;
.
.
.
public AddItemDetails(String office_name,String ref_no,String I_name,...){
this.office_name = new SimpleStringProperty(office_name);
this.ref_no = new SimpleStringProperty(ref_no);
this.I_name = new SimpleStringProperty(I_name);
.
.
.
// + getters
Setting the cellValueFactory-s for each column:
colofiice_name.setCellValueFactory(data -> data.getValue().office_nameProperty());
colref_name.setCellValueFactory(data -> data.getValue().colref_nameProperty());
item_name.setCellValueFactory(data -> data.getValue().item_nameProperty());
Adding a new item to the tableView:
tableView.getItems().add(new AddItemDetails("Office","Ref","I_name",...));
After these steps it should work.
EDIT
You can use an
ObservableList<AddItemDetails> myData = FXCollecctions.observableArraylist();
for storing the data, then:
tableView.setItems(myData);
then you can add and remove elements to and from this list, and it will update the data in tableview too.Like:
mydata.add(new AddItemDetails(...));
myData.remove(...);

Is it possible to add multiple table view using a single Controller class and multiple entity Class in Java FX?

My question is about JavaFX-9.
I am trying to handle two table view in one FXML Controller class. But it is giving me a Null pointer exception. How to solve this?
The first TableView (studentTable) is working and second table(rTable) is not working.
home.java:
package Home;
import javafx.application.Application;
import javafx.fxml.FXMLLoader;
import javafx.scene.Parent;
import javafx.scene.Scene;
import javafx.stage.Stage;
public class home extends Application{
public void start(Stage stage)throws Exception{
Parent root=(Parent) FXMLLoader.load(getClass().getResource("Home.fxml"));
Scene scene=new Scene(root);
stage.setScene(scene);
stage.setTitle("Result Analysis System");
stage.show();
}
public static void main(String[] args){
launch(args);
}
}
homeController.java
package Home;
/*_____________________
Error in this file
_____________________*/
import dbUtils.dbConnection;
//import Home.rControl;
//import Home.resultData;
import javafx.collections.FXCollections;
import javafx.collections.ObservableArray;
import javafx.collections.ObservableList;
import javafx.event.ActionEvent;
import javafx.fxml.FXML;
import javafx.fxml.Initializable;
import javafx.scene.control.*;
//import javafx.scene.control.DatePicker;
import javafx.scene.control.cell.PropertyValueFactory;
//import Home.resultData;
import java.net.URL;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.List;
import java.util.ResourceBundle;
public class homeController /*extends resultController*/ implements Initializable{
//Student tab
#FXML
private TextField usn;
#FXML
private TextField name;
#FXML
protected TableView<studentData> studentTable;
#FXML
protected TableColumn<studentData,String> USNcolumn;
#FXML
protected TableColumn<studentData,String> Namecolumn;
//Result tab
#FXML
private TextField rusn;
#FXML
private ComboBox<option> rSelectSem;
#FXML
private TextField rSub1;
#FXML
private TextField rSub2;
#FXML
private TextField rSub3;
#FXML
private TextField rSub4;
#FXML
private TextField rSub5;
#FXML
private TextField rSub6;
#FXML
private TextField rSub7;
#FXML
private TextField rSub8;
#FXML
private Button rAdd;
#FXML
private Button rLoad;
#FXML
private Button rClear;
#FXML
private ComboBox<option> rSelectSem1;
#FXML
private Button rLoad1;
#FXML
private TableView<resultData> rTable;
#FXML
private TableColumn<resultData,String> rColusn;
#FXML
private TableColumn<resultData,String> rColname;
#FXML
private TableColumn<resultData,Integer> rColsub1;
#FXML
private TableColumn<resultData,Integer> rColsub2;
#FXML
private TableColumn<resultData,Integer> rColsub3;
#FXML
private TableColumn<resultData,Integer> rColsub4;
#FXML
private TableColumn<resultData,Integer> rColsub5;
#FXML
private TableColumn<resultData,Integer> rColsub6;
#FXML
private TableColumn<resultData,Integer> rColsub7;
#FXML
private TableColumn<resultData,Integer> rColsub8;
#FXML
private TableColumn<resultData,Integer> rColtotal;
//Analyze tab
#FXML
private ComboBox<option> aSelectSem;
#FXML
private Button aHighmarks;
#FXML
private Button aPassedstudent;
#FXML
private Button aFailedstudent;
#FXML
private Button aListallstudent;
#FXML
private Button adistiction;
#FXML
private Button aFirstclass;
#FXML
private Button aSecondclass;
#FXML
private TableView<analysisData> aTable;
#FXML
private TableColumn<analysisData,String> aColusn;
#FXML
private TableColumn<analysisData,String> aColname;
#FXML
private TableColumn<analysisData,Integer> aColsub1;
#FXML
private TableColumn<analysisData,Integer> aColsub2;
#FXML
private TableColumn<analysisData,Integer> aColsub3;
#FXML
private TableColumn<analysisData,Integer> aColsub4;
#FXML
private TableColumn<analysisData,Integer> aColsub5;
#FXML
private TableColumn<analysisData,Integer> aColsub6;
#FXML
private TableColumn<analysisData,Integer> aColsub7;
#FXML
private TableColumn<analysisData,Integer> aColsub8;
#FXML
private TableColumn<analysisData,Integer> aColtotal;
protected dbConnection dc;
protected ObservableList<studentData> data;
//private ObservableList<resultData> list;
protected String sql = "SELECT * FROM studentDet";
#Override
public void initialize(URL url, ResourceBundle rb){
this.dc = new dbConnection();
this.rSelectSem.setItems(FXCollections.observableArrayList(option.values()));
this.rSelectSem1.setItems(FXCollections.observableArrayList(option.values()));
this.aSelectSem.setItems(FXCollections.observableArrayList(option.values()));
// rTable.setItems(list);
}
//Load student data in student tab
//This is working
#FXML
private void loadStudentData(ActionEvent event) throws SQLException{
try {
Connection conn = dbConnection.getConnection();
this.data = FXCollections.observableArrayList();
ResultSet rs = conn.createStatement().executeQuery(sql);
while (rs.next()){
this.data.add(new studentData(rs.getString(1),rs.getString(2)));
}
}
catch (SQLException e){
System.err.println("error" + e);
}
this.USNcolumn.setCellValueFactory(new PropertyValueFactory<studentData,String>("USN"));
this.Namecolumn.setCellValueFactory(new PropertyValueFactory<studentData,String>( "Name"));
this.studentTable.setItems(null);
this.studentTable.setItems(this.data);
}
//This is working
//Add student in student tab
#FXML
private void addStudent(ActionEvent actionEvent) {
String sqlInsert="INSERT INTO studentDet(USN,Name) VALUES(?,?)";
try {
//here the name is same but it doesn't matter because this is a local variable
Connection conn=dbConnection.getConnection();
PreparedStatement statement=conn.prepareStatement(sqlInsert);
statement.setString(1,this.usn.getText());
statement.setString(2,this.name.getText());
statement.execute();
conn.close();
} catch (SQLException e) {
e.printStackTrace();
}
}
//This is working
//Clear feilds in Student tab
#FXML
private void clearFields(ActionEvent actionEvent)
{
this.usn.setText("");
this.name.setText("");
}
#FXML
private void rclearFields(ActionEvent actionEvent)
{
this.rusn.setText("");
this.rSub1.setText("");
this.rSub2.setText("");
this.rSub3.setText("");
this.rSub4.setText("");
this.rSub5.setText("");
this.rSub6.setText("");
this.rSub7.setText("");
this.rSub8.setText("");
}
//This is working
//Add marks to sem in Result tab
#FXML
private void addSemMarks(ActionEvent actionEvent)
{
String sqlInsert;
try {
switch (((option) this.rSelectSem.getValue()).toString()) {
case "SEM1":
sqlInsert="INSERT INTO SEM1(USN,SUB1E,SUB2E,SUB3E,SUB4E,SUB5E,SUB6E,SUB7E,SUB8E) VALUES(?,?,?,?,?,?,?,?,?)";
semMarksAdd(sqlInsert);
break;
case "SEM2":
sqlInsert="INSERT INTO SEM2(USN,SUB1E,SUB2E,SUB3E,SUB4E,SUB5E,SUB6E,SUB7E,SUB8E) VALUES(?,?,?,?,?,?,?,?,?)";
semMarksAdd(sqlInsert);
break;
case "SEM3":
sqlInsert="INSERT INTO SEM3(USN,SUB1E,SUB2E,SUB3E,SUB4E,SUB5E,SUB6E,SUB7E,SUB8E) VALUES(?,?,?,?,?,?,?,?,?)";
semMarksAdd(sqlInsert);
break;
case "SEM4":
sqlInsert="INSERT INTO SEM4(USN,SUB1E,SUB2E,SUB3E,SUB4E,SUB5E,SUB6E,SUB7E,SUB8E) VALUES(?,?,?,?,?,?,?,?,?)";
semMarksAdd(sqlInsert);
break;
case "SEM5":
sqlInsert="INSERT INTO SEM5(USN,SUB1E,SUB2E,SUB3E,SUB4E,SUB5E,SUB6E,SUB7E,SUB8E) VALUES(?,?,?,?,?,?,?,?,?)";
semMarksAdd(sqlInsert);
break;
case "SEM6":
sqlInsert="INSERT INTO SEM6(USN,SUB1E,SUB2E,SUB3E,SUB4E,SUB5E,SUB6E,SUB7E,SUB8E) VALUES(?,?,?,?,?,?,?,?,?)";
semMarksAdd(sqlInsert);
break;
case "SEM7":
sqlInsert="INSERT INTO SEM7(USN,SUB1E,SUB2E,SUB3E,SUB4E,SUB5E,SUB6E,SUB7E,SUB8E) VALUES(?,?,?,?,?,?,?,?,?)";
semMarksAdd(sqlInsert);
break;
case "SEM8":
sqlInsert="INSERT INTO SEM8(USN,SUB1E,SUB2E,SUB3E,SUB4E,SUB5E,SUB6E,SUB7E,SUB8E) VALUES(?,?,?,?,?,?,?,?,?)";
semMarksAdd(sqlInsert);
break;
}
}
catch (Exception ex){
ex.printStackTrace();
}
}
private void semMarksAdd(String sqlinsert){
//String sqlInsert="INSERT INTO SEM1(USN,SUB1E,SUB2E,SUB3E,SUB4E,SUB5E,SUB6E,SUB7E,SUB8E) VALUES(?,?,?,?,?,?,?,?,?)";
try {
//here the name is same but it doesn't matter because this is a local variable
Connection conn=dbConnection.getConnection();
PreparedStatement statement=conn.prepareStatement(sqlinsert);
statement.setString(1,this.rusn.getText());
statement.setString(2,this.rSub1.getText());
statement.setString(3,this.rSub2.getText());
statement.setString(4,this.rSub3.getText());
statement.setString(5,this.rSub4.getText());
statement.setString(6,this.rSub5.getText());
statement.setString(7,this.rSub6.getText());
statement.setString(8,this.rSub7.getText());
statement.setString(9,this.rSub8.getText());
statement.execute();
conn.close();
}
catch (SQLException e) {
e.printStackTrace();
}
}
//#########################################################Stable upto here
//From here it is giving error
//TO LOAD STUDENT MARKS DATA IN RESULT TABLE
/*#FXML
private void loadResultData(ActionEvent actionEvent){
String sqlLoad;
try {
switch (((option) this.rSelectSem.getValue()).toString()) {
case "SEM1":
sqlLoad = "SELECT USN,SUB1E,SUB2E,SUB3E,SUB4E,SUB5E,SUB6E,SUB7E,SUB8E,TOTAL FROM SEM1";
loadRdata(sqlLoad);
break;
case "SEM2":
sqlLoad = "SELECT USN,SUB1E,SUB2E,SUB3E,SUB4E,SUB5E,SUB6E,SUB7E,SUB8E,TOTAL FROM SEM2";
loadRdata(sqlLoad);
break;
case "SEM3":
sqlLoad = "SELECT USN,SUB1E,SUB2E,SUB3E,SUB4E,SUB5E,SUB6E,SUB7E,SUB8E,TOTAL FROM SEM3";
loadRdata(sqlLoad);
break;
case "SEM4":
sqlLoad = "SELECT USN,SUB1E,SUB2E,SUB3E,SUB4E,SUB5E,SUB6E,SUB7E,SUB8E,TOTAL FROM SEM4";
loadRdata(sqlLoad);
break;
case "SEM5":
sqlLoad = "SELECT USN,SUB1E,SUB2E,SUB3E,SUB4E,SUB5E,SUB6E,SUB7E,SUB8E,TOTAL FROM SEM5";
loadRdata(sqlLoad);
break;
case "SEM6":
sqlLoad = "SELECT USN,SUB1E,SUB2E,SUB3E,SUB4E,SUB5E,SUB6E,SUB7E,SUB8E,TOTAL FROM SEM6";
loadRdata(sqlLoad);
break;
case "SEM7":
sqlLoad = "SELECT USN,SUB1E,SUB2E,SUB3E,SUB4E,SUB5E,SUB6E,SUB7E,SUB8E,TOTAL FROM SEM7";
loadRdata(sqlLoad);
break;
case "SEM8":
sqlLoad = "SELECT USN,SUB1E,SUB2E,SUB3E,SUB4E,SUB5E,SUB6E,SUB7E,SUB8E,TOTAL FROM SEM8";
loadRdata(sqlLoad);
break;
}
}
catch (Exception ex){
ex.printStackTrace();
}
}*/
#FXML
public void loadResultData(ActionEvent actionEvent) {
String sqlLoad = "SELECT USN,SUB1E,SUB2E,SUB3E,SUB4E,SUB5E,SUB6E,SUB7E,SUB8E,TOTAL FROM SEM1";
loadRdata(sqlLoad); //Error here
}
/*private void loadResultData(ActionEvent actionEvent) {
String sqlLoad = "SELECT USN,SUB1E,SUB2E,SUB3E,SUB4E,SUB5E,SUB6E,SUB7E,SUB8E,TOTAL FROM SEM1";
rc.loadRdata(sqlLoad);
}*/
private ObservableList<resultData> list = FXCollections.observableArrayList();
private void loadRdata(String sqlLoad) {
try {
Connection conn = dbConnection.getConnection();
this.list = FXCollections.observableArrayList();
//System.out.println("Hello"); //working
ResultSet rs = conn.createStatement().executeQuery(sqlLoad);
while (rs.next()) {
//System.out.println(rs.getString(1)); //Working
this.list.add(new resultData(rs.getString(1), rs.getInt(2), rs.getInt(3), rs.getInt(4), rs.getInt(5), rs.getInt(6), rs.getInt(7), rs.getInt(8), rs.getInt(9), rs.getInt(10)));
}
// this.rColusn.setCellValueFactory("Helloworld"); //working
this.rColusn.setCellValueFactory(new PropertyValueFactory<resultData, String>("rColUsn"));
this.rColsub1.setCellValueFactory(new PropertyValueFactory<resultData, Integer>("rColSub1"));
this.rColsub2.setCellValueFactory(new PropertyValueFactory<resultData, Integer>("rColSub2"));
this.rColsub3.setCellValueFactory(new PropertyValueFactory<resultData, Integer>("rColSub3"));
this.rColsub4.setCellValueFactory(new PropertyValueFactory<resultData, Integer>("rColSub4"));
this.rColsub5.setCellValueFactory(new PropertyValueFactory<resultData, Integer>("rColSub5"));
this.rColsub6.setCellValueFactory(new PropertyValueFactory<resultData, Integer>("rColSub6"));
this.rColsub7.setCellValueFactory(new PropertyValueFactory<resultData, Integer>("rColSub7"));
this.rColsub8.setCellValueFactory(new PropertyValueFactory<resultData, Integer>("rColSub8"));
this.rColtotal.setCellValueFactory(new PropertyValueFactory<resultData, Integer>("rColTotal"));
System.out.println("after block1");
list.clear();
System.out.println("after block2");
rTable.setItems(list);// CAUSING NULL POINTER EXCEPTION
System.out.println("after block3");//NOT PRINTING
}
catch (Exception e) {//System.out.println(" "+e);
System.err.println("error" + e);
}
}
}
resultData.java
package Home;
import javafx.beans.property.IntegerProperty;
import javafx.beans.property.SimpleIntegerProperty;
import javafx.beans.property.SimpleStringProperty;
import javafx.beans.property.StringProperty;
public class resultData {
private final StringProperty rColUsn;
//private final StringProperty rColName;
private final IntegerProperty rColSub1;
private final IntegerProperty rColSub2;
private final IntegerProperty rColSub3;
private final IntegerProperty rColSub4;
private final IntegerProperty rColSub5;
private final IntegerProperty rColSub6;
private final IntegerProperty rColSub7;
private final IntegerProperty rColSub8;
private final IntegerProperty rColTotal;
public resultData(String usn,Integer sub1,Integer sub2,Integer sub3,Integer sub4,Integer sub5,Integer sub6,Integer sub7,Integer sub8,Integer total){
System.out.println("result data");// TWO TIMES IT WORKS,BUT THE THERE ARE 10 COLUMNS AND IT SHOULD PRINT 10 TIMES.
rColUsn = new SimpleStringProperty(usn);
//this.rColName = new SimpleStringProperty(name);
rColSub1 = new SimpleIntegerProperty(sub1);
rColSub2 = new SimpleIntegerProperty(sub2);
rColSub3 = new SimpleIntegerProperty(sub3);
rColSub4 = new SimpleIntegerProperty(sub4);
rColSub5 = new SimpleIntegerProperty(sub5);
rColSub6 = new SimpleIntegerProperty(sub6);
rColSub7 = new SimpleIntegerProperty(sub7);
rColSub8 = new SimpleIntegerProperty(sub8);
rColTotal = new SimpleIntegerProperty(total);
}
public String getrColUsn() {
return rColUsn.get();
}
public StringProperty rColUsnProperty() {
return rColUsn;
}
public void setrColUsn(String rColUsn) {
this.rColUsn.set(rColUsn);
}
public int getrColSub1() {
return rColSub1.get();
}
public IntegerProperty rColSub1Property() {
return rColSub1;
}
public void setrColSub1(int rColSub1) {
this.rColSub1.set(rColSub1);
}
public int getrColSub2() {
return rColSub2.get();
}
public IntegerProperty rColSub2Property() {
return rColSub2;
}
public void setrColSub2(int rColSub2) {
this.rColSub2.set(rColSub2);
}
public int getrColSub3() {
return rColSub3.get();
}
public IntegerProperty rColSub3Property() {
return rColSub3;
}
public void setrColSub3(int rColSub3) {
this.rColSub3.set(rColSub3);
}
public int getrColSub4() {
return rColSub4.get();
}
public IntegerProperty rColSub4Property() {
return rColSub4;
}
public void setrColSub4(int rColSub4) {
this.rColSub4.set(rColSub4);
}
public int getrColSub5() {
return rColSub5.get();
}
public IntegerProperty rColSub5Property() {
return rColSub5;
}
public void setrColSub5(int rColSub5) {
this.rColSub5.set(rColSub5);
}
public int getrColSub6() {
return rColSub6.get();
}
public IntegerProperty rColSub6Property() {
return rColSub6;
}
public void setrColSub6(int rColSub6) {
this.rColSub6.set(rColSub6);
}
public int getrColSub7() {
return rColSub7.get();
}
public IntegerProperty rColSub7Property() {
return rColSub7;
}
public void setrColSub7(int rColSub7) {
this.rColSub7.set(rColSub7);
}
public int getrColSub8() {
return rColSub8.get();
}
public IntegerProperty rColSub8Property() {
return rColSub8;
}
public void setrColSub8(int rColSub8) {
this.rColSub8.set(rColSub8);
}
public int getrColTotal() {
return rColTotal.get();
}
public IntegerProperty rColTotalProperty() {
return rColTotal;
}
public void setrColTotal(int rColTotal) {
this.rColTotal.set(rColTotal);
}
}
studentData.java
package Home;
import javafx.beans.property.SimpleStringProperty;
import javafx.beans.property.StringProperty;
public class studentData{
private final StringProperty USN;
private final StringProperty Name;
public studentData(String usn,String name){
this.USN=new SimpleStringProperty(usn);
this.Name=new SimpleStringProperty(name);
}
public String getUSN() {
return USN.get();
}
public StringProperty USNProperty() {
return USN;
}
public void setUSN(String USN) {
this.USN.set(USN);
}
public String getName() {
return Name.get();
}
public StringProperty nameProperty() {
return Name;
}
public void setName(String name) {
this.Name.set(name);
}
}
Commnd Line Output:
"C:\Program Files\Java\jdk-9.0.1\bin\java" "-javaagent:C:\Program
Files\JetBrains\IntelliJ IDEA 2017.2.5\lib\idea_rt.jar=55700:C:\Program
Files\JetBrains\IntelliJ IDEA 2017.2.5\bin" -Dfile.encoding=UTF-8 -
/* WHEN CLICKING TABLE DISPLAY BUTTON FIRST TIME */
result data
result data
after block1
after block2
errorjava.lang.NullPointerException
/* WHEN CLICKING TABLE DISPLAY BUTTON SECOND TIME*/
errorjava.lang.NullPointerException
result data
result data
after block1
after block2
You need to set a value into the table.
This is not going to work (remove from your loadRdata method):
this.rTable.setItems(null); // giving error here:Null pointer Exception
this.rTable.setItems(this.list);
Initialize your ObservableList first:
private ObservableList<resultData> list = FXCollections.observableArrayList();
Then in your method loadRdata clear the values rather than initializing like you are now.
list.clear();
At the end of you initialize() method you can add the values
rTable.setItems(list);

Not showing data in tableview Javafx

this is my Controller class
public class IWS5Controller extends BaseScreenController implements Initializable{
private Stage dialogStage;
#FXML
private TableView<Table1Model> table1;
#FXML
private TableView<Table2Model> table2;
#FXML
private TableView<Table3Model> table3;
#FXML
private TableColumn<Table1Model,String> col1;
#FXML
private TableColumn<Table1Model,String> col2;
#FXML
private TableColumn<Table2Model,Integer> col3;
#FXML
private TableColumn<Table2Model,Integer> col4;
#FXML
private TableColumn<Table3Model,Integer> col5;
#FXML
private TableColumn<Table3Model,Integer> col6;
#FXML
private TableColumn<Table3Model,Integer> col7;
#FXML
private TableColumn<Table3Model,String> col8;
#FXML
private Button closeBtn;
#Autowired
private ScreensContoller screenController;
/*#Autowired
private CheckBoxController checkboxController;*/
#Override
public void initialize(URL location, ResourceBundle resources) {
// TODO Auto-generated method stub
}
#FXML
public void initialize(){
PropertyValueFactory<Table1Model, String> first =
new PropertyValueFactory<Table1Model, String>("synid");
PropertyValueFactory<Table1Model, String> second =
new PropertyValueFactory<Table1Model, String>("help");
PropertyValueFactory<Table2Model, Integer> third =
new PropertyValueFactory<Table2Model, Integer>("page");
PropertyValueFactory<Table2Model, Integer> fourth =
new PropertyValueFactory<Table2Model, Integer>("line");
PropertyValueFactory<Table3Model, Integer> fifth =
new PropertyValueFactory<Table3Model, Integer>("recordDate");
PropertyValueFactory<Table3Model, Integer> sixth =
new PropertyValueFactory<Table3Model, Integer>("diagnosisDate");
PropertyValueFactory<Table3Model, Integer> seventh =
new PropertyValueFactory<Table3Model, Integer>("age");
PropertyValueFactory<Table3Model, String> eigth =
new PropertyValueFactory<Table3Model, String>("note");
col1.setCellValueFactory(first);
col2.setCellValueFactory(second);
col3.setCellValueFactory(third);
col4.setCellValueFactory(fourth);
col5.setCellValueFactory(fifth);
col6.setCellValueFactory(sixth);
col7.setCellValueFactory(seventh);
col8.setCellValueFactory(eigth);
//setting up the table data source
Iws5Data data = new Iws5Data();
ObservableList<Table1Model> table1Items = data.getData();
ObservableList<Table2Model> table2Items = data.getData2();
ObservableList<Table3Model> table3Items = data.getData3();
table1.setItems( table1Items );
table2.setItems( table2Items );
table3.setItems( table3Items );
closeBtn.setOnAction((ActionEvent event)->{
dialogStage.close();
});
}
}
Table 1 model:
package com.iws.model;
import javafx.beans.property.FloatProperty;
import javafx.beans.property.IntegerProperty;
import javafx.beans.property.SimpleBooleanProperty;
import javafx.beans.property.SimpleIntegerProperty;
import javafx.beans.property.SimpleStringProperty;
import javafx.beans.property.StringProperty;
public class Table1Model {
private final SimpleStringProperty synid;
private final SimpleStringProperty help;
public Table1Model(String synid,String help){
this.synid = new SimpleStringProperty(synid);
this.help = new SimpleStringProperty(help);
}
public String getSynid() {
return synid.get();
}
public void setSynid(String synid) {
this.synid.set( synid );
}
public String getHelp() {
return help.get();
}
public void setHelp(String help) {
this.help.set( help );
}
}
Table 2 model:
package com.iws.model;
import javafx.beans.property.IntegerProperty;
import javafx.beans.property.SimpleIntegerProperty;
import javafx.beans.property.SimpleStringProperty;
public class Table2Model {
private final SimpleIntegerProperty page;
private final SimpleIntegerProperty line;
public Table2Model(Integer page, Integer line) {
this.page = new SimpleIntegerProperty(page);
this.line = new SimpleIntegerProperty(line);
}
public Integer getPage() {
return page.get();
}
public void setPage(Integer page) {
this.page.set( page );
}
public Integer getLine() {
return line.get();
}
public void setLine(Integer line) {
this.line.set( line );
}
}
Table 3 Model:
package com.iws.model;
import javafx.beans.property.SimpleIntegerProperty;
import javafx.beans.property.SimpleStringProperty;
public class Table3Model {
private final SimpleIntegerProperty recordDate;
private final SimpleIntegerProperty diagnosisDate;
private final SimpleIntegerProperty age;
private final SimpleStringProperty note;
public Table3Model(Integer recordDate, Integer diagnosisDate, Integer age, String note) {
this.recordDate = new SimpleIntegerProperty(recordDate);
this.diagnosisDate = new SimpleIntegerProperty(diagnosisDate);
this.age = new SimpleIntegerProperty(age);
this.note = new SimpleStringProperty(note);
}
public Integer getRecordDate() {
return recordDate.get();
}
public void setRecordDate(Integer recordDate) {
this.recordDate.set( recordDate );
}
public Integer getDiagnosisDate() {
return diagnosisDate.get();
}
public void setDiagnosisDate(Integer diagnosisDate) {
this.diagnosisDate.set( diagnosisDate );
}
public Integer getAge() {
return age.get();
}
public void setAge(Integer age) {
this.age.set( age );
}
public String getNote() {
return note.get();
}
public void setNote(String note) {
this.note.set( note );
}
}
Data Class(hardcoded data)
package com.iws.database;
import com.iws.model.Table1Model;
import com.iws.model.Table2Model;
import com.iws.model.Table3Model;
import javafx.collections.FXCollections;
import javafx.collections.ObservableList;
public class Iws5Data {
private final ObservableList<Table1Model> data1 =
FXCollections.observableArrayList();
public ObservableList<Table1Model> getData(){
return data1;
}
private final ObservableList<Table2Model> data2 =
FXCollections.observableArrayList();
public ObservableList<Table2Model> getData2(){
return data2;
}
private final ObservableList<Table3Model> data3 =
FXCollections.observableArrayList();
public ObservableList<Table3Model> getData3(){
return data3;
}
public Iws5Data(){
data1.add(new Table1Model("Synid", "help"));
data2.add(new Table2Model(3434, 2343));
data3.add(new Table3Model(22, 543, 5, "note"));
}
}
All 3 tables are being shown correctly without any error. But no data in it is shown.
If there is any other way of adding hardcoded data to tableview then that will also be helpfull.

JavaFX TableView: Show sorted items + Background Task

I'm working with Javafx and I'm struggling to get a sorted table in place when using background Tasks to update. In the code here, which can be run standalone, I update a table in background.
What I'd like to do is that this table gets updated, and stays sorted in chronological order, so older train times appear at the top, and later ones at the bottom. The example produces times that are the opposite order on purpose, to see if sorting works.
I run some tests before I added concurrent update to the table, and the way I would do it is by calling:
private final ObservableList<StationBoardLine> data = FXCollections.observableArrayList(
new StationBoardLine("RE", "17:14", "Basel Bad Bf", "Basel SBB", "+3", "RE 5343"));
SortedList<StationBoardLine> sorted = new SortedList<>(data, new DelayComparator());
table.setItems(sorted);
However, now I'm not setting the items, but using the background task together with ReadOnlyObjectProperty and ReadOnlyObjectWrapper to append to it.
So, my question is, how can I make sure that as items are added, the list remains ordered? I've tried to see if I could reorder the list inside the call to Platform.runLater but didn't seem to work.
The link between the task updating the table and the table is set is here:
table.itemsProperty().bind(task.partialResultsProperty());
Thanks for help,
Galder
The way I would do it is by updating an ObservableList by the background task and use it as a "source" to create a SortedList. This SortedList would then act as the source of "items" to the TableView.
A general structure would be :
public class MyClass {
private TableView<T> tableView = new TableView;
private ObservableList<T> sourceList = FXCollections.observableArrayList();
public MyClass() {
...
SortedList<T> sortedList = new SortedList<>(sourceList, new MyComparator());
tableView.setItems(sortedList);
...
new Task<Void> {
protected Void call() {
... // Some background data fetch
Platform.runLater(() -> sourceList.add(data));
return null;
}
};
}
}
For your scenario, I would go with something that you already have. Therefore, instead of creating a new ObservableList to be used as a source for your SortedList, I would use the list returned by Task#getPartialResults().
The DelayComparator uses the value of the delay to compare and show the data in the TableView.
import javafx.application.Application;
import javafx.application.Platform;
import javafx.beans.property.SimpleStringProperty;
import javafx.collections.FXCollections;
import javafx.collections.ObservableList;
import javafx.collections.transformation.SortedList;
import javafx.concurrent.Task;
import javafx.scene.Scene;
import javafx.scene.control.TableColumn;
import javafx.scene.control.TableView;
import javafx.scene.control.cell.PropertyValueFactory;
import javafx.scene.layout.BorderPane;
import javafx.stage.Stage;
import java.util.Comparator;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
public class App extends Application {
private TableView<StationBoardLine> table = new TableView<>();
private final ExecutorService exec = Executors.newSingleThreadExecutor();
public static void main(String[] args) {
launch(args);
}
#Override
public void start(Stage stage) {
BorderPane root = new BorderPane();
Scene scene = new Scene(root, 800, 600);
table.setColumnResizePolicy(TableView.CONSTRAINED_RESIZE_POLICY);
table.setEditable(true);
TableColumn typeCol = getTableCol("Type", 10, "type");
TableColumn departureCol = getTableCol("Departure", 30, "departure");
TableColumn stationCol = getTableCol("Station", 200, "station");
TableColumn destinationCol = getTableCol("Destination", 200, "destination");
TableColumn delayCol = getTableCol("Delay", 20, "delay");
TableColumn trainName = getTableCol("Train Name", 50, "trainName");
table.getColumns().addAll(
typeCol, departureCol, stationCol, destinationCol, delayCol, trainName);
root.setCenter(table);
PartialResultsTask task = new PartialResultsTask();
SortedList<StationBoardLine> sorted = new SortedList<>(task.getPartialResults(), new DelayComparator());
table.setItems(sorted);
exec.submit(task);
stage.setTitle("Swiss Transport Delays Board");
stage.setScene(scene);
stage.show();
}
private TableColumn getTableCol(String colName, int minWidth, String fieldName) {
TableColumn<StationBoardLine, String> typeCol = new TableColumn<>(colName);
typeCol.setMinWidth(minWidth);
typeCol.setCellValueFactory(new PropertyValueFactory<>(fieldName));
return typeCol;
}
static final class DelayComparator implements Comparator<StationBoardLine> {
#Override
public int compare(StationBoardLine o1, StationBoardLine o2) {
return o1.getDelay().compareTo(o2.getDelay());
}
}
public class PartialResultsTask extends Task<Void> {
private ObservableList<StationBoardLine>partialResults = FXCollections.observableArrayList();
public final ObservableList<StationBoardLine> getPartialResults() {
return partialResults;
}
#Override protected Void call() throws Exception {
System.out.println("Creating station board entries...");
for (int i=5; i >= 1; i--) {
Thread.sleep(1000);
if (isCancelled()) break;
StationBoardLine l = new StationBoardLine(
"ICE", "16:" + i, "Basel Bad Bf", "Chur", String.valueOf(i), "ICE 75");
Platform.runLater(() -> partialResults.add(l));
}
return null;
}
}
public static final class StationBoardLine {
private final SimpleStringProperty type;
private final SimpleStringProperty departure;
private final SimpleStringProperty station;
private final SimpleStringProperty destination;
private final SimpleStringProperty delay;
private final SimpleStringProperty trainName;
StationBoardLine(String type,
String departure,
String station,
String destination,
String delay,
String trainName) {
this.type = new SimpleStringProperty(type);
this.departure = new SimpleStringProperty(departure);
this.station = new SimpleStringProperty(station);
this.destination = new SimpleStringProperty(destination);
this.delay = new SimpleStringProperty(delay);
this.trainName = new SimpleStringProperty(trainName);
}
public String getType() {
return type.get();
}
public SimpleStringProperty typeProperty() {
return type;
}
public void setType(String type) {
this.type.set(type);
}
public String getDeparture() {
return departure.get();
}
public SimpleStringProperty departureProperty() {
return departure;
}
public void setDeparture(String departure) {
this.departure.set(departure);
}
public String getStation() {
return station.get();
}
public SimpleStringProperty stationProperty() {
return station;
}
public void setStation(String station) {
this.station.set(station);
}
public String getDestination() {
return destination.get();
}
public SimpleStringProperty destinationProperty() {
return destination;
}
public void setDestination(String destination) {
this.destination.set(destination);
}
public String getDelay() {
return delay.get();
}
public SimpleStringProperty delayProperty() {
return delay;
}
public void setDelay(String delay) {
this.delay.set(delay);
}
public String getTrainName() {
return trainName.get();
}
public SimpleStringProperty trainNameProperty() {
return trainName;
}
public void setTrainName(String trainName) {
this.trainName.set(trainName);
}
}
}

Resources