How to get appointment details when an AppointmentPane is clicked - JFXtras

て烟熏妆下的殇ゞ 提交于 2019-12-24 11:28:48

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!