0

I am using a GWTFlexTable and have one issue: I am deleting any row after that when I do try to add new row it is giving rowcount value including removed row because of this while iterating last row giving IndexOutOfBoundsException.

for( count=0; count < table.getRowCount(); count++ )
{

}

Giving this exception

[FATAL] Uncaught Exception:
 [java] java.lang.IndexOutOfBoundsException:
 [java] Column index: 0, Column size: 0
Baz
  • 36,440
  • 11
  • 68
  • 94
Amit Sinha
  • 11
  • 5

2 Answers2

0

Please have a look at demo on GWT Showcase - FlexTable.

Here is the code to add/remove a row directly from show case. Use these method to perform these operation. Always check the row count first before doing any operation.

/**
 * Add a row to the flex table.
 */
private void addRow(FlexTable flexTable) {
    int numRows = flexTable.getRowCount();
    flexTable.setWidget(numRows, 0, widget1));
    flexTable.setWidget(numRows, 1, widget2));
    flexTable.getFlexCellFormatter().setRowSpan(0, 1, numRows + 1);
}

/**
 * Remove a row from the flex table.
 */
private void removeRow(FlexTable flexTable) {
    int numRows = flexTable.getRowCount();
    if (numRows > 1) {
        flexTable.removeRow(numRows - 1);
        flexTable.getFlexCellFormatter().setRowSpan(0, 1, numRows - 1);
    }
}
Braj
  • 46,415
  • 5
  • 60
  • 76
  • Please can your share a testable and minimal running code. – Braj Apr 14 '14 at 15:01
  • sorry i can not put images it needs 10 reputation..... it is happening when i do delete last row .i have checked with firebug it showing empty tag – Amit Sinha Apr 15 '14 at 06:44
0

if u using button to remove row.. write a click handler when remove a perticular row.

 Button removeSelectedRow = new Button();
 removeSelectedRow.addClickHandler(new ClickHandler() {
  @Override
  public void onClick(ClickEvent event) {
    int rowIndex = flexTable.getCellForEvent(event).getRowIndex();
    flexTable.removeRow(rowIndex);
  }
}); 

Don't use rowCount().
use like this getRowIndex() position. It will help to remove a row it can present in any order or any position or anywhere in your page. is this your need?

Prasanth Np
  • 175
  • 6
  • i am using rowCount to check name under name column should not repeat ....getting exception at last Row iteration . – Amit Sinha Apr 16 '14 at 07:38
  • this might be work, for (int count=flextable.getRowCount()-1; count>=0;count--){ flextable.removeRow(i); } this will remove all rows from flex table. – Prasanth Np Apr 16 '14 at 09:37