JavaFx - How can I pass the value from ListView (window 2) to Buttons (window1) ListView is contained Hi guys, I am a beginner in Java, so this is maybe not some smart question, but I cannot find answer online tho.
(there is a photo at the end for the interface.)
In my codes, I have a window/stage to show an overview/calendar, the admin user should be able to make reservations for different users. So when he firstly selects one time slot, then clicks "make reservation", there is now another window poping up with a list view, by clicking one band's name and then clicking "confirm", the selected time slot should have the name of the band.
My question is, how can I show the band's name on the time slot after clicking "confirm"? (so how can I pass the newValue-the last click out from listview?) Now I am only able to put the code "setText" in the listView, so before confirm, the time slot already has the name. I tried to "setText" on the button-action of "confirm", but does not work.
code for list view:
ObservableList<String> strlist = FXCollections.observableArrayList("Band1","Band2","Band3");
javafx.scene.control.ListView<String> listview = new javafx.scene.control.ListView<>(strlist);
listview.setItems(strlist);
listview.setPrefSize(200, 150);
listview.getSelectionModel().selectedItemProperty().addListener(
(ObservableValue<? extends String> observable,String oldValue, String newValue) ->{
timeslot.setText(newValue);
System.out.println(newValue);
}
);
code for the confirm button:
confirm.setOnAction(new EventHandler <ActionEvent>(){
public void handle (ActionEvent event) {
TimeSlot timeslot = week.getSelectedSlot();
timeslot.setReserved();
timeslot.setStyle("-fx-font:12 arial;-fx-base:#F95F62;");
week.unmarkSelectedSlot();
window.close();
}
});
PHOTO:the interface photo with listview window and the time slot window
The listview window's code is in a private class MakeReservation, this is inside the timeslot-view codes.