2 Replies Latest reply: Feb 8, 2013 1:40 AM by Marcello RSS

    ListView.getSelectionModel().select( i) issue

    Marcello
      This might be a minor issue however I spent already too much time on this to figure out:

      Why does the the next item not getting selected, when pressing the button ? It gets focused but I does not get "blue", like it would get when I click on it ??
           final ListView<String> fileList = new ListView<String>();
           ObservableList<String> items =FXCollections.observableArrayList( "111", "222");
           fileList.setItems( items);
           fileList.getSelectionModel().setSelectionMode(SelectionMode.SINGLE);
           fileList.getSelectionModel().select(0);     
      
           borderPane.setCenter( fileList);
                
                     
           Button b =new Button();
           b.setOnAction( new EventHandler<ActionEvent>() {
                     @Override
                     public void handle(ActionEvent arg0) {                    
                          fileList.getSelectionModel().select(1);                                   
                     }
                });  
      
           borderPane.Bottom( b);
      Edited by: Marcello on 07.02.2013 05:58
        • 1. Re: ListView.getSelectionModel().select( i) issue
          shakir.gusaroff
          Hi. It is not an issue. It works as expected.
          From Caspian.css document:
            /* When the ListView is _not_ focused, we show alternate selection colors */
          .list-cell:filled:selected:focused, .list-cell:filled:selected, .list-view:horizontal .list-cell:filled:selected {
              -fx-background-color: lightgray;
              -fx-text-fill: -fx-selection-bar-text;
          }
          You have 2 options:
          1.     Add fileList.requestFocus() before selection:
                  Button b = new Button();
                  b.setOnAction(new EventHandler<ActionEvent>() {
                      @Override
                      public void handle(ActionEvent arg0) {
                          fileList.requestFocus();
                          fileList.getSelectionModel().select(1);
          
          
          
                      }
                  });
          2. Create custom.css fie and override the Caspian.css settings.
          • 2. Re: ListView.getSelectionModel().select( i) issue
            Marcello
            Thanks Shakir,

            This in fact works.