Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-8115768

TableView and TablePosition problem

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Fixed
    • Icon: P4 P4
    • fx2.1
    • fx2.1
    • javafx
    • Windows XP, Netbeans 7.1, JavaFX 2.1 b12 (7_feb_2012)

      Hi,

      I have a little problem about the use of TablePosition for the TableView control.

      I use a listener on tablePosition to get the selected rows. Here's the code:
       {{{
      ObservableList<TablePosition> tablePositions = getSelectionModel().getSelectedCells();
              tablePositions.addListener(new ListChangeListener<TablePosition>(){
                  public void onChanged(Change<? extends TablePosition> change) {
                      ObservableList<? extends TablePosition> tablePositions = change.getList();
                      List<AccountLine> accountLines = new ArrayList<AccountLine>();
                      for (Iterator<? extends TablePosition> it = tablePositions.iterator(); it.hasNext();) {
                          TablePosition tablePosition = it.next();
                          int row = tablePosition.getRow();
                          Log.getLogger().fine("getItems().size()="+getItems().size()+",row="+row);
                          if ((getItems().size()>0) && (row<=getItems().size())){
                              AccountLine accountLine = getItems().get(row);
                              accountLines.add(accountLine);
                          }else {
                              Log.getLogger().severe("Unable to get row for row " + row + " and items size()="+getItems().size());
                          }
       }}}

      After clearing the items of the tableView ( getItems().clear() ), I set items for tableView ( getItems().setAll(_items) ), it throws an exception 'cause of the row index which is -14 (see below).

      My question is, why row index is -14. Normally if I clear the table, there will be no selection of rows, row index of table position must be -1 ?

       {{{
      [AccountTable$2:onChanged] FINE getItems().size()=1203,row=-14
      ecomptes2.view.DialogView$1 handle
      GRAVE: null
      java.lang.ArrayIndexOutOfBoundsException: -14
      at java.util.ArrayList.get(ArrayList.java:324)
      at com.sun.javafx.collections.ObservableListWrapper.get(Unknown Source)
      at ecomptes2.control.AccountTable$2.onChanged(AccountTable.java:85)
       }}}

            jgiles Jonathan Giles
            duke J. Duke
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported: