-1

How do you refresh the data in your tableView on button Press using FXML?

I have the following file structure and I want to refresh the data in this table when a button is pressed. Would anyone know a solution?

public class MyTable {

private final SimpleStringProperty ID = new SimpleStringProperty("");
private final SimpleStringProperty ParticipantID = new SimpleStringProperty("");


public Positions() {
    this("", "")
}

public Positions(String ID, String ParticipantID) {

    setMemberID(ID);
    setParticipantID(ParticipantID); 
}


public String getParticipantID() {
    return  ParticipantID.get();
}

public void setParticipantID(String pID) {
    ParticipantID.set(ParticipantID); 

}

public String getID() {
    return ID.get();
}

public void ID(String cID) {
    ID.set(ID);
}
}

I initialise this table on the tablecontroller file for this. Now on button press I would like the tableview which is an FXML file update itself. How do I do this?

CodeGeek123
  • 4,341
  • 8
  • 50
  • 79

2 Answers2

1

Thanks but the solution to this was to have one global ObservableList<> data which you then modify on a button press action event. What I was trying to do was create another observable list which does not work.

CodeGeek123
  • 4,341
  • 8
  • 50
  • 79
1

If you want to update only on button press and not as data is modified that is the default way ?

The simplest way to do would be to create a bean to which all data is updated and the make the button synchronize it with the bean that represents a row in your table.

public class TableBean
{
 MyTable child;
 String Id;
 String ParticipantId;
 public void Sync()
 {
  child.Id(Id);
  child.setParticipantID(ParticipantId);
 }
}

It is important to note that your methods violate JavaFX convetion , this probably brakes things. An example of 3 methods used for every propery in JavaFX.

private final IntegerProperty ratio = new SimpleIntegerProperty();

public int getRatio() {
    return ratio.get();
}

public void setRatio(int value) {
    ratio.set(value);
}

public IntegerProperty ratioProperty() {
    return ratio;
}
user3224416
  • 522
  • 5
  • 15