ChangeListener on javafx ListView is called only once?

16 Views Asked by At

I'am trying to use a ListView control to show a list of Objects which are derived from LinkedList<>; The elements in the Linkedlist dosent matter and do not need to shown.

My problem is, that the ChangeListner is only called once when I select any of the shown List elements and i down know why?

The following code works, but the Changelisteners changed() method is called only on the fist selection iam doing. When I click on another ListView cell it gets selected visualy but the changed method gets not called. What I'am doing wrong?

When i use this code with an non derived Class/Object it works. But not with Session<E> extends LinkedList<E>

On initialization I do the following:

@Override
    public void initialize(URL arg0, ResourceBundle arg1) 
    {
        LinkedList<Session<Exercise>> sessions = new LinkedList<Session<Exercise>>();
        sessions.add(new Session<Exercise>("Dummy1"));
        sessions.add(new Session<Exercise>("Dummy2"));
        sessions.add(new Session<Exercise>("Dummy3"));
        
        lvSessions.setCellFactory(new SessionCellFactory());
        
        ObservableList<Session<Exercise>> items = FXCollections.observableArrayList();
        items.setAll(sessions);
        lvSessions.setItems(items);
        
        lvSessions.getSelectionModel().selectedItemProperty().addListener(new ChangeListener<Session<Exercise>>() 
        {

            @Override
            public void changed(ObservableValue<? extends Session<Exercise>> arg0, Session<Exercise> arg1,
                    Session<Exercise> arg2) {
                
                System.out.println("changed");
                
            }
        });
        
    }

Here is my CellFactory class:

public class SessionCellFactory implements Callback<ListView<Session<Exercise>>, ListCell<Session<Exercise>>> 
{

    @Override
    public ListCell<Session<Exercise>> call(ListView<Session<Exercise>> lvSessions) 
    {
        ListCell<Session<Exercise>> listCell = new ListCell<Session<Exercise>>()
            {
                @Override
                protected void updateItem(Session<Exercise> session, boolean empty) {
                    super.updateItem(session, empty);
                    //this.getStyleClass().add("");
                    if(!empty)
                    {   
                        this.setText(session.getName());
                    }                   
                }
                
            };
        
        return listCell;        
    }
}

Here is a part of the Session class

public class Session<E> extends LinkedList<E>{
    ...
}
0

There are 0 best solutions below