问题
I am working on a project a i want to get the selected data of tableview but i am using FXML.
I have codes for no-FXML but i am unable to use it for FXML.
code:
public class person1 {
private final StringProperty firstName = new SimpleStringProperty("");
private final StringProperty surname = new SimpleStringProperty("");
private final StringProperty goodnameof1 = new SimpleStringProperty("");
public person1(String firstName) {
setFirstName(firstName);
}
public String getFirstName() {
return firstName.get();
}
public void setFirstName(String name) {
this.firstName.set(name);
}
public StringProperty firstNameProperty() {
return firstName;
}
public String getSurname() {
return surname.get();
}
public void setSurname(String name) {
surname.set(name);
}
public StringProperty surnameProperty() {
return surname;
}
public String getGoodnameof1() {
return goodnameof1.get();
}
public void setGoodnameof1(String name) {
goodnameof1.set(name);
}
}
TestController:
public class TestController implements Initializable {
/**
* Initializes the controller class.
*/
@Override
public void initialize(URL url, ResourceBundle rb) {
}
@FXML
private TableView<person1> table;
@FXML
void add(ActionEvent event) {
table.getItems().add(new person1("dsdsd"));
}
}
now i want to know what i code to get selected data from tableview
Please help me.
Thank You.
回答1:
If you want the selected row index, then use
table.getSelectionModel().getSelectedIndex();
来源:https://stackoverflow.com/questions/24445252/javafx-how-to-get-selected-data-from-tableview-using-fxml