问题
I would like to print out an appointment's summary
and description
when a user clicks on a particular appointment retrieved from the database.
I'm trying to implement this with something like:
lAgenda.selectedAppointments().addListener(new ListChangeListener<Appointment>() {
@Override
public void onChanged(Change<? extends Appointment> c) {
System.out.println(c.toString());
}
});
I however, only get this:
com.sun.javafx.collections.NonIterableChange$GenericAddRemoveChange@1ef0f08
com.sun.javafx.collections.NonIterableChange$SimpleAddChange@1c3e48b
com.sun.javafx.collections.NonIterableChange$GenericAddRemoveChange@d57e70
com.sun.javafx.collections.NonIterableChange$SimpleAddChange@6022e2
com.sun.javafx.collections.NonIterableChange$GenericAddRemoveChange@54ddc1
How can I retrieve other items, like the ID of the row in the database row the appointment is being retrieved from? Thank you all.
回答1:
You are using the right property to be notified of the selection change.
You received a ListChangeListener.Change. As described in the javadoc, a change should be used in the this way :
lAgenda.selectedAppointments().addListener(new ListChangeListener< Appointment >() {
public void onChanged(Change<? extends Appointment> c) {
while (c.next()) {
if (c.wasPermutated()) {
for (int i = c.getFrom(); i < c.getTo(); ++i) {
//permutate
}
} else if (c.wasUpdated()) {
//update item
} else {
for (Appointment a : c.getRemoved()) {
}
for (Appointment a : c.getAddedSubList()) {
printAppointment(a);
}
}
}
}
});
Now, you could print out appointment summary and description :
private void printAppointment(Appointment a) {
System.out(a.getSummary());
System.out(a.getDescription());
}
If you need some specific properties on the appointment object (like a database id), you could create your appointment class by extending AppointmentImpl or by implementing Appointment
来源:https://stackoverflow.com/questions/23970420/how-to-get-appointment-details-when-an-appointmentpane-is-clicked-jfxtras