Can't load data to TableView - java

I can't load data into table. I have class Player with name, lastName, etc. I want to insert name, lastname into table player over textfield.
public class CoreAppFXMLController implements Initializable {
#FXML
private Button addBtn;
#FXML
private Button deleteBtn;
#FXML
private Tab playersTab;
#FXML
private Tab coachesTab;
#FXML
private TextField playerNameFld;
#FXML
private TextField playerLNFld;
#FXML
private TextField playerNumberFld;
#FXML
private TextField playerPointsFld;
#FXML
private ChoiceBox<String> positionCb;
#FXML
private TableColumn<Player, String> playerNameCol;
#FXML
private TableColumn<Player, String> playerLNCol;
#FXML
private TableColumn<Player, String> playerNumberCol;
#FXML
private TableColumn<Player, String> playerPointsCol;
#FXML
private TableView<Player> playerTable;
ObservableList<Player> data = FXCollections.observableArrayList();
public class Player {
private String name;
private String lastName;
private String number;
private String points;
public Player(String name, String lastName, String number, String points) {
this.name = name;
this.lastName = lastName;
this.number = number;
this.points = points;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getLastName() {
return lastName;
}
public void setLastName(String lastName) {
this.lastName = lastName;
}
public String getNumber() {
return number;
}
public void setNumber(String number) {
this.number = number;
}
public String getPoints() {
return points;
}
public void setPoints(String points) {
this.points = points;
}
}
/**
* Initializes the controller class.
*/
public void initialize(URL url, ResourceBundle rb) {
positionCb.setItems(FXCollections.observableArrayList("PLAYMAKER",
"SHOOTER", "WING", "CENTER", "CENTER-WING"));
playerNameCol
.setCellValueFactory(new PropertyValueFactory<Player, String>(
"name"));
playerLNCol
.setCellValueFactory(new PropertyValueFactory<Player, String>(
"lastName"));
playerNumberCol
.setCellValueFactory(new PropertyValueFactory<Player, String>(
"number"));
playerPointsCol
.setCellValueFactory(new PropertyValueFactory<Player, String>(
"points"));
playerTable.setItems(data);
}
public void addBtnAction(ActionEvent event) {
data.add(new Player(playerNameFld.getText(), playerLNFld.getText(),
playerNumberFld.getText(), playerPointsFld.getText()));
playerNameFld.clear();
playerLNFld.clear();
playerNumberFld.clear();
playerPointsFld.clear();
}
public void deleteBtnAction(ActionEvent event) {
}
}
I am doing exactly same thing as shown here: http://docs.oracle.com/javase/8/javafx/user-interface-tutorial/table-view.htm#CJAGAAEE
But I can't get it to work. Can anyone help me?

It's not exactly the same as the example and if you're using Java 7, then it might not work the same regardless. Try setting up your Player class to use SimpleStringProperty for the member variables and then add a *Property() method for each of them that returns the member. For example:
public class Player
{
private SimpleStringProperty name;
public Player(String name)
{
this.name.set(name);
}
public SimpleStringProperty nameProperty() { return name; }
public String getName() { return name.get(); }
public void setName(String name) { this.name.set(name); }
}
Try that and add in the rest of your members the same way.

Related

JavaFX: How do I fill a table view with 2 different classes with the same super class

I have 3 classes the first one is Library Item this is the super class. The other two classes are Book and Movie. When I want to fill my table view I want to make sure the correct property is called when populating the table view. I know it is easier to just call the director and author the same for ease of use, but I want to get it working for learning purposes. I have left out packages and imports for relevance.
LibraryItem class
public abstract class LibraryItem {
private int itemCode;
private String title;
private boolean availability;
private int memberIdentifier;
private LocalDate dateLent;
protected LibraryItem(int itemCode, String title, boolean availability, int memberIdentifier, LocalDate dateLent) {
this.itemCode = itemCode;
this.title = title;
this.availability = availability;
this.memberIdentifier = memberIdentifier;
this.dateLent = dateLent;
}
public int getItemCode() {
return itemCode;
}
public String getTitle() {
return title;
}
public boolean isAvailability() {
return availability;
}
public void setAvailability(boolean availability) {
this.availability = availability;
}
public int getMemberIdentifier() {
return memberIdentifier;
}
public void setMemberIdentifier(int memberIdentifier) {
this.memberIdentifier = memberIdentifier;
}
public LocalDate getDateLent() {
return dateLent;
}
public void setDateLent(LocalDate dateLent) {
this.dateLent = dateLent;
}
}
Book class
public class Book extends LibraryItem {
private String author;
protected Book(int itemCode, String title, boolean isLent, int memberIdentifier, LocalDate dateLent, String author) {
super(itemCode, title, isLent, memberIdentifier, dateLent);
this.author = author;
}
}
Movie class
public class Movie extends LibraryItem {
private String director;
protected Movie(int itemCode, String title, boolean isLent, int memberIdentifier, LocalDate dateLent, String director) {
super(itemCode, title, isLent, memberIdentifier, dateLent);
this.director = director;
}
}
I was thinking maybe there is some kind of check I can do for each row implemented so the correct value will be given,
This was my attempt:
public class CollectionController implements Initializable {
#FXML
private TableView<LibraryItem> libraryItemsTable;
#FXML
private TableColumn<LibraryItem, String> itemCodeColumn;
#FXML
private TableColumn<LibraryItem, String> availableColumn;
#FXML
private TableColumn<LibraryItem, String> titleColumn;
#FXML
private TableColumn<LibraryItem, String> authorDirectorColumn;
private LibraryService libraryService = new LibraryService();
#Override
public void initialize(URL location, ResourceBundle resources) {
initializeTableView();
}
private void initializeTableView() {
List<LibraryItem> libraryItems = libraryService.getLibraryItems();
itemCodeColumn.setCellValueFactory(new PropertyValueFactory<>("itemCode"));
availableColumn.setCellValueFactory(new PropertyValueFactory<>("availability"));
titleColumn.setCellValueFactory(new PropertyValueFactory<>("title"));
// implement here check for each new row
if (checkIfBook(row))
authorDirectorColumn.setCellValueFactory(new PropertyValueFactory<>("author"));
else
authorDirectorColumn.setCellValueFactory(new PropertyValueFactory<>("director"));
//
libraryItemsTable.getItems().addAll(libraryItems);
}
If you follow the advice here and avoid the use of PropertyValueFactory, the solution becomes reasonably clear:
titleColumn.setCellValueFactory(data ->
new SimpleStringProperty(data.getValue().getTitle()));
authorDirectorColumn.setCellValueFactory(data -> {
LibraryItem item = data.getValue();
if (item instanceof Book book) {
return new SimpleStringProperty(book.getAuthor());
} else if (item instanceof Movie movie) {
return new SimpleStringProperty(movie.getProducer());
} else {
return null ;
}
});
Here's a complete example (I simplified the model classes for brevity, but retained enough to demonstrate the point):
import javafx.application.Application;
import javafx.beans.property.SimpleStringProperty;
import javafx.scene.Scene;
import javafx.scene.control.TableColumn;
import javafx.scene.control.TableView;
import javafx.scene.layout.BorderPane;
import javafx.stage.Stage;
import java.io.IOException;
public class HelloApplication extends Application {
#Override
public void start(Stage stage) throws IOException {
TableView<LibraryItem> table = new TableView<>();
TableColumn<LibraryItem, String> titleColumn = new TableColumn<>("Title");
TableColumn<LibraryItem, String> authorProducerColumn = new TableColumn<>("Author/Producer");
table.getColumns().add(titleColumn);
table.getColumns().add(authorProducerColumn);
titleColumn.setCellValueFactory(data -> new SimpleStringProperty(data.getValue().getTitle()));
authorProducerColumn.setCellValueFactory(data -> {
LibraryItem item = data.getValue();
if (item instanceof Book book) {
return new SimpleStringProperty(book.getAuthor());
} else if (item instanceof Movie movie) {
return new SimpleStringProperty(movie.getProducer());
} else return null ;
});
for (int i = 1 ; i <= 10 ; i++) {
Book book = new Book("Book "+i, "Author "+i);
Movie movie = new Movie("Movie "+i, "Producer "+i);
table.getItems().addAll(book, movie);
}
BorderPane root = new BorderPane(table);
Scene scene = new Scene(root);
stage.setScene(scene);
stage.show();
}
public class LibraryItem {
private String title ;
public LibraryItem(String title) {
this.title = title ;
}
public String getTitle() {
return title;
}
public void setTitle(String title) {
this.title = title;
}
}
public class Movie extends LibraryItem {
private String producer ;
public Movie(String title, String producer) {
super(title);
this.producer = producer ;
}
public String getProducer() {
return producer;
}
public void setProducer(String producer) {
this.producer = producer;
}
}
public class Book extends LibraryItem {
private String author ;
public Book(String title, String author) {
super(title);
this.author = author ;
}
public String getAuthor() {
return author;
}
public void setAuthor(String author) {
this.author = author;
}
}
public static void main(String[] args) {
launch();
}
}

adding button to javafx table view with condition

I am new to javafx and working on to add Button to TableView with condition .
if the condition is true it will add the button and if false the button will not add to the tableView . i google it but i did not find any suggetion or solution .
is there any way to achieve it. thank in advance.
here is my controller
#FXML
TableView<Employee> employeeTable;
#FXML
TableColumn<Employee, Integer> col_id;
#FXML
TableColumn<Employee, String> col_fatherName;
#FXML
TableColumn<Employee, String> col_CNIC;
#FXML
TableColumn<Employee, String> col_gender;
#FXML
TableColumn<Employee, Button> update;
List<Employee> employees = new ArrayList<>();
ObservableList<Employee> obs = FXCollections.observableArrayList();
private Employee data;
#Override
public void initialize(URL url, ResourceBundle rb) {
// TODO
setColumnProperties();
addButtonToTable();
addDeleteButton();
loadData();
}
private void loadData() {
employees = employeeDAO.findAllEmployees();
obs = FXCollections.observableArrayList(employees);
employeeTable.getItems().clear();
employeeTable.getItems().addAll(obs);
}
public void setColumnProperties() {
col_id.setCellValueFactory(new PropertyValueFactory<Employee, Integer>("id"));
col_fatherName.setCellValueFactory(new PropertyValueFactory<Employee, String>("fatherName"));
col_CNIC.setCellValueFactory(new PropertyValueFactory<Employee, String>("cnic"));
col_gender.setCellValueFactory(new PropertyValueFactory<Employee, String>("name"));
}
private void addButtonToTable() {
Callback<TableColumn<Employee, Button>, TableCell<Employee, Button>> cellFactory = new Callback<TableColumn<Employee, Button>, TableCell<Employee, Button>>() {
#Override
public TableCell<Employee, Button> call(final TableColumn<Employee, Button> param) {
final TableCell<Employee, Button> cell = new TableCell<Employee, Button>() {
Image imgEdit = new Image(getClass().getResourceAsStream("/images/download.png"));
{
}
#Override
public void updateItem(Button item, boolean empty) {
super.updateItem(item, empty);
edite=new Button("Btn"); // global btn
if (empty) {
setGraphic(null);
} else {
// here i am trying to write condition
Iterator ite= employeeDAO.findAllEmployees().iterator();
while (ite.hasNext()){
Employee employee=(Employee) ite.next();
if (employee.getName().equals("jnk"))
{
edite.setOnAction((ActionEvent event) -> {
System.out.println( edite.getId());
data = getTableView().getItems().get(getIndex());
fatherName.setText(data.getFatherName());
CNIC.setText(data.getCnic());
name.setText(data.getName());
register_btn.setText("Update");
});
edite.setStyle("-fx-background-color: transparent;");
ImageView iv = new ImageView();
iv.setFitHeight(50);
iv.setFitWidth(50);
iv.setImage(imgEdit);
iv.setPreserveRatio(true);
iv.setSmooth(true);
iv.setCache(true);
edite.setGraphic(iv);
setGraphic(edite);
setText(null);
}
else{
System.out.println("not working");
}
}
}
}
};
return cell;
}
;
};
update.setCellFactory(cellFactory);
employeeTable.getColumns().add(update);
register_btn.setText("Register");
}
my goal is add the button if the Name='jnk'
but after the condition is true it add buttons to all row.
My Employee Class
public class EMployee{
private int id;
private String name;
private String cnic;
private String skill;
private String dob;
private String fatherName;
private String gender;
private int value;
setter and getter
}
EmployeeDao Class is
Public Class EmployeeDAO extends JdbcDaoSupport {
public List<Employee> findAllEmployees() {
List<Employee> empList = new ArrayList<>();
String query = "select * from employee";
getJdbcTemplate().query(query,
new BeanPropertyRowMapper<Employee>(Employee.class));
return empList;
}
}

How to receive data in particular row of tableView in javafx?

I am working on rfid and I am receiving data in tableView from database mysql which matches the UID of my rfid tag.
But when I tap the another RFid tag, the previous data is overwritten by the new one.
But I want the new data in next row of tableview.
This is my Controller code:
public class detectController {
#FXML
private ResourceBundle resources;
#FXML
private URL location;
#FXML
private TableView<detectBean> tableView;
#FXML
private TextField txtSTID;
ObservableList<detectBean> list;
public static SerialPort s1;
static String temp="";
static String temp1="";
static void doAlert(String msg)
{
Alert alert=new Alert(AlertType.INFORMATION);
alert.setTitle("Alert..");
alert.setContentText(msg);
alert.show();
}
ObservableList<detectBean> getRecordsFromTableSome(String sID) throws FileNotFoundException
{
list=FXCollections.observableArrayList();
try {
pst=con.prepareStatement("select * from stuRegis where studentID=?");
pst.setString(1, sID);
ResultSet rs= pst.executeQuery();
while(rs.next())
{
String studentID=rs.getString("studentID");
String name=rs.getString("name");
String sroll=rs.getString("sroll");
String clas=rs.getString("clas");
String fname=rs.getString("fname");
String contact=rs.getString("contact");
String pic = rs.getString("pic");
FileInputStream photo=new FileInputStream(pic);
Image image1 = new Image(photo, 100, 100, false, false);
detectBean bean=new detectBean(studentID, name, sroll, clas, fname, contact, new ImageView(image1));
list.add(bean);
}
}
catch (SQLException e)
{
// TODO Auto-generated catch block
e.printStackTrace();
}
return list;
}
/////////////////////////////////////////////////////
#FXML
void doFetch(ActionEvent event) throws IOException{
String a = recall();
txtSTID.setText(a);
ObservableList<detectBean> list=getRecordsFromTableSome(a);
tableView.setItems(list);
}
#FXML
void doComClose(ActionEvent event) {
if(s1.closePort()){
doAlert("Port Closed");
System.out.println("Port closed successFully");
}else{
doAlert("Failed to Close Port");
System.out.println("Failed to close port");
}
}
#FXML
void doOpenCom(ActionEvent event) {
port();
}
/////////////////////////////////////////////////////
public static void port()
{
SerialPort[] s=SerialPort.getCommPorts();
for(SerialPort port:s){
System.out.println(""+port.getSystemPortName());
s1=SerialPort.getCommPort(port.getSystemPortName());
if(s1.openPort()){
doAlert("Port Opened");
System.out.println("Port opened successFully ");
}else{
doAlert("Failed to Open Port");
System.out.println("Failed to open port");
}
}
s1.setBaudRate(9600);
}
public static String recall() throws IOException
{
InputStream is=s1.getInputStream();
StringBuilder st = new StringBuilder();
for(int i=0,x=0;true;i++){
//for (int i =0;i<11;i++){
st=st.append((char)is.read());
temp1=st.toString();
if(temp1.length()==13)
{ System.out.print(temp1);
//System.out.print(temp);
//System.out.print(temp1.length());
break;
}
System.out.print(temp1);
}
//System.out.print(""+(char)is.read());
temp=temp1.substring(0,11);
System.out.print(temp.length());
System.gc();
return temp;
}
//////////////////////////////////////////////////////
PreparedStatement pst;
Connection con;
#FXML
void initialize() throws IOException, FileNotFoundException {
con=MysqlConnection.doConnect();
TableColumn<detectBean, String> studentID=new TableColumn<detectBean, String>("Student ID");//Dikhava Title
studentID.setCellValueFactory(new PropertyValueFactory<>("studentID"));//bean field name
studentID.setMinWidth(90);
TableColumn<detectBean, String> name=new TableColumn<detectBean, String>("Name");//Dikhava Title
name.setCellValueFactory(new PropertyValueFactory<>("name"));//bean field name
TableColumn<detectBean, String> sroll=new TableColumn<detectBean, String>("Roll No.");//Dikhava Title
sroll.setCellValueFactory(new PropertyValueFactory<>("sroll"));//bean field name
TableColumn<detectBean, String> clas=new TableColumn<detectBean, String>("Class");//Dikhava Title
clas.setCellValueFactory(new PropertyValueFactory<>("clas"));//bean field name
TableColumn<detectBean, String> fname=new TableColumn<detectBean, String>("Father's Name");//Dikhava Title
fname.setCellValueFactory(new PropertyValueFactory<>("fname"));//bean field name
TableColumn<detectBean, String> contact=new TableColumn<detectBean, String>("Contact No.");//Dikhava Title
contact.setCellValueFactory(new PropertyValueFactory<>("contact"));//bean field name
contact.setMinWidth(90);
TableColumn<detectBean, Image> pic=new TableColumn<detectBean, Image>("Image");//Dikhava Title
pic.setCellValueFactory(new PropertyValueFactory<>("pic"));//bean field name
pic.setMinWidth(110);
tableView.getColumns().clear();
tableView.getColumns().addAll(studentID,name,sroll,clas,fname,contact,pic);
}
}
DetectBean :
public class detectBean {
String studentID;
String name;
String sroll;
String clas;
String fname;
String contact;
ImageView image;
public detectBean(String studentID, String name, String sroll, String clas, String fname, String contact, ImageView image) {
super();
this.studentID = studentID;
this.name = name;
this.sroll = sroll;
this.clas = clas;
this.fname = fname;
this.contact = contact;
this.image = image;
}
public String getsID() {
return studentID;
}
public void setsID(String studentID) {
this.studentID = studentID;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getSroll() {
return sroll;
}
public void setSroll(String sroll) {
this.sroll = sroll;
}
public String getClas() {
return clas;
}
public void setClas(String clas) {
this.clas = clas;
}
public String getFname() {
return fname;
}
public void setFname(String fname) {
this.fname = fname;
}
public String getContact() {
return contact;
}
public void setContact(String contact) {
this.contact = contact;
}
public ImageView getPic() {
return image;
}
public void setPic(String pic) {
this.image = image;
}
}
Image of output:
not displaying data in student ID column
I think the Problem is:
tableView.setItems(list);
resets the list.
try instead :
tableview.getItems().addAll(list);
Alternatively only set an ObservableList in the initialize method and change that list directly in you query.
public class detectController {
//....
#FXML
private TableView<detectBean> tableView;
ObservableList<detectBean> list;
///....
/////////////////////////////////////////////////////
#FXML
void doFetch(ActionEvent event) throws IOException{
String a = recall();
txtSTID.setText(a);
ObservableList<detectBean> list=getRecordsFromTableSome(a);
/// here!!!
// tableView.setItems(list);
tableView.getItems().addAll(list);
}

Vaadin field group is not working

I am trying to implement vaadin fieldgroup but it does not bind the values.
And it is giving me the following error :
Communication problem
Invalid JSON response from server:
Here is my code.
Model Class:
public class LoggedCustomer {
private String Id;
private String Name;
private String Cell;
private String email;
private String address;
public String getId() {
return Id;
}
public void setId(String id) {
Id = id;
}
public String getName() {
return Name;
}
public void setName(String name) {
Name = name;
}
public String getCell() {
return Cell;
}
public void setCell(String cell) {
Cell = cell;
}
public String getEmail() {
return email;
}
public void setEmail(String email) {
this.email = email;
}
public String getAddress() {
return address;
}
public void setAddress(String address) {
this.address = address;
}
}
Customer Layout Class:
public class CustomerFormView extends FormLayout {
#PropertyId("id")
private TextField id = new TextField("Customer Id");
#PropertyId("name")
private TextField name = new TextField("Customer Name");
#PropertyId("cell")
private TextField cell = new TextField("Customer Cell Number");
#PropertyId("email")
private TextField email = new TextField("Customer Email");
#PropertyId("address")
private TextField address = new TextField("Customer Address");
public CustomerFormView() {
setSpacing(true);
addComponent(id);
addComponent(name);
addComponent(cell);
addComponent(email);
addComponent(address);
}
}
Main UI Class:
public class LoggedIn extends UI {
#WebServlet(value = "/loggedin", asyncSupported = true)
#VaadinServletConfiguration(productionMode = false, ui = LoggedIn.class)
public static class Servlet extends VaadinServlet {
}
#Override
protected void init(VaadinRequest request) {
HorizontalLayout hori = new HorizontalLayout();
setContent(hori);
hori.setSpacing(true);
hori.setMargin(true);
Item customer = createCustomer();
hori.addComponent(createView(customer));
hori.addComponent(displayCustomer(customer));
}
private Layout createView(Item item) {
VerticalLayout formLayout = new VerticalLayout();
formLayout.setMargin(true);
formLayout.setSizeFull();
CustomerFormView productEditLayout = new CustomerFormView();
formLayout.addComponent(productEditLayout);
final FieldGroup binder = new FieldGroup(item);
binder.bindMemberFields(productEditLayout);
HorizontalLayout footer = new HorizontalLayout();
footer.setSpacing(true);
footer.addComponent(new Button("Save", new Button.ClickListener() {
#Override
public void buttonClick(ClickEvent event) {
try {
binder.commit();
} catch (InvalidValueException e) {
} catch (CommitException e) {
}
}
}));
footer.addComponent(new Button("Cancel", new Button.ClickListener() {
#Override
public void buttonClick(ClickEvent event) {
binder.discard();
}
}));
formLayout.addComponent(footer);
return formLayout;
}
private Layout displayCustomer(Item item) {
FormLayout layout = new FormLayout();
Label name = new Label();
name.setPropertyDataSource(item.getItemProperty("name"));
name.setCaption("Name");
layout.addComponent(name);
return layout;
}
private static Item createCustomer() {
LoggedCustomer customer = new LoggedCustomer();
customer.setName("");
customer.setId("");
customer.setCell("");
customer.setEmail("");
customer.setAddress("");
return new BeanItem<LoggedCustomer>(customer);
}
}
this is the full code of my application in which I am working but the fieldgroup binder is not working and giving the error.
Kindly someone help me to identify where is the problem and what i am doing wrong in the code.
I shall be thankful.... :)

get string when selected from tableview javafx

So in basic form I want to get selected text from tableview.
I have my SetCoachFXML in which I have tableview, with some data in it. Next to that I have choose button. How can I get selected text from tableview when I click on choose button?
http://imgur.com/wA6n792
I tried suggestion from here but I get nothing.
Here is my setcoach controller class:
public class SetCoachController implements Initializable {
//Kolone i tabela za prikazivanje trenera
#FXML
private TableColumn<Coaches, String> coachesNameCol;
#FXML
private TableColumn<Coaches, String> coachesLNCol;
#FXML
private TableView<Coaches> coachTable;
#FXML
private Button chooseBtn;
#FXML
private Button cancelBtn;
private ObservableList<Coaches> coachesData;
#Override
public void initialize(URL url, ResourceBundle rb) {
coachesNameCol
.setCellValueFactory(new PropertyValueFactory<Coaches, String>(
"name"));
coachesLNCol
.setCellValueFactory(new PropertyValueFactory<Coaches, String>(
"lastName"));
coachesData = FXCollections.observableArrayList();
coachTable.setItems(coachesData);
coachTable.setEditable(false);
CoachBase.get();
loadCoachesData();
}
//sql upit
public void loadCoachesData() {
try {
ResultSet rs = CoachBase.query("SELECT * FROM CoachTable");
coachesData.clear();
while (rs.next()) {
coachesData.add(new Coaches(rs.getString("Name"), rs.getString("Lastname")));
}
} catch (Exception e) {
System.out.println("" + e.getMessage());
}
}
public void chooseAction(ActionEvent event) {
Coaches coach = (Coaches) coachTable.getSelectionModel().getSelectedItem();
System.out.println(coach.getcoachesName());
}
public void cancelAction(ActionEvent event) {
Stage stage = (Stage) cancelBtn.getScene().getWindow();
stage.close();
}
and my Coaches class:
public class Coaches {
private SimpleIntegerProperty id = new SimpleIntegerProperty();
private SimpleStringProperty name = new SimpleStringProperty();
private SimpleStringProperty lastName = new SimpleStringProperty();
private SimpleIntegerProperty age = new SimpleIntegerProperty();
public Coaches(Integer id, String name, String lastName, int age) {
this.name.setValue(name);
this.lastName.setValue(lastName);
this.age.setValue(age);
}
public Coaches(String name, String lastName) {
this.name.setValue(name);
this.lastName.setValue(lastName);
}
public Integer getId() {
if (id == null) {
return 0;
}
return id.getValue();
}
public String getcoachesName() {
if (name != null) {
return "";
}
return name.getValueSafe();
}
public String getlastName() {
if (lastName != null) {
return "";
}
return lastName.getValueSafe();
}
public Integer getAge() {
if (age == null) {
return 0;
}
return age.getValue();
}
public SimpleIntegerProperty IdProperty() {
return id;
}
public SimpleStringProperty nameProperty() {
return name;
}
public SimpleStringProperty lastNameProperty() {
return lastName;
}
public SimpleIntegerProperty ageProperty() {
return age;
}
}
I think what's happening is when you click on the button, your loosing focus on the selected cell which means when you try to retrieving data, nothing happens.
What you need to do is make sure that when you click on the button, the cell/row is still selected.
Then you can do something like:
// To retrieve
Person person = (Person)taview.getSelectionModel().getSelectedItem();
System.out.println(person.getName());

Categories