Grid extends JPanel implements GridSelectionModel.Listener { public void removeDataRows(int... dataRowIndexes) { if (dataRowIndexes.length == 0) { return; } removeFiller(); int offset = 0; int selectedCount = 0; for (int dataRowIndex : dataRowIndexes) { Assert.argument(dataRowIndex >= 0, "rowIndexes"); int rowIndex = dataRowIndex + 1 - offset; Assert.state(rowIndex >= 1, "rowIndex"); selectedCount += isDataRowSelected(dataRowIndex) ? 1 : 0; List<JComponent> componentRow = componentRows.get(rowIndex); removeComponentRowIntern(componentRow); componentRows.remove(rowIndex); offset++; } int rowIndex0 = dataRowIndexes[0] + 1; for (int rowIndex = rowIndex0; rowIndex < componentRows.size(); rowIndex++) { addComponentRowIntern(componentRows.get(rowIndex), rowIndex); } addFiller(); fireComponentsChanged(); if (selectedCount > 0) { for (int dataRowIndex : dataRowIndexes) { selectionModel.removeSelectedRowIndex(dataRowIndex); } } } Grid(int columnCount, boolean showSelectionColumn);  Grid(TableLayout tableLayout, boolean showSelectionColumn); @Override TableLayout getLayout(); @Override void setLayout(LayoutManager mgr); GridSelectionModel getSelectionModel(); void setSelectionModel(GridSelectionModel selectionModel); boolean getShowSelectionColumn(); void setShowSelectionColumn(boolean showSelectionColumn); int getColumnCount(); int getDataColumnCount(); int getRowCount(); int getDataRowCount(); JComponent getComponent(int rowIndex, int colIndex); JComponent setComponent(int rowIndex, int colIndex, JComponent component); int findRowIndex(JComponent component); int findDataRowIndex(JComponent component); void setHeaderRow(JComponent... components); JComponent[] getDataRow(int dataRowIndex); void addDataRow(JComponent... components); void removeDataRow(int dataRowIndex); void removeDataRows(int... dataRowIndexes); void moveDataRowUp(int dataRowIndex); void moveDataRowDown(int dataRowIndex); boolean isDataRowSelected(int dataRowIndex); int getSelectedDataRowCount(); int getSelectedDataRowIndex(); int[] getSelectedDataRowIndexes(); void setSelectedDataRowIndexes(int... dataRowIndexes); @Override void gridSelectionChanged(GridSelectionModel.Event event);  }
@Test public void testRemoveDataRows() throws Exception { Grid grid = new Grid(4, true); JLabel c1 = new JLabel(); JLabel c2 = new JLabel(); JLabel c3 = new JLabel(); JLabel c4 = new JLabel(); JLabel c5 = new JLabel(); JLabel c6 = new JLabel(); grid.addDataRow(c1, c2, c3); grid.addDataRow(new JLabel(), new JLabel(), new JLabel()); grid.addDataRow(c4, c5, c6); grid.addDataRow(new JLabel(), new JLabel(), new JLabel()); grid.removeDataRows(1, 3); assertEquals(2, grid.getDataRowCount()); assertEquals(3, grid.getRowCount()); assertEquals(JCheckBox.class, grid.getComponent(1, 0).getClass()); assertSame(c1, grid.getComponent(1, 1)); assertSame(c2, grid.getComponent(1, 2)); assertSame(c3, grid.getComponent(1, 3)); assertEquals(JCheckBox.class, grid.getComponent(2, 0).getClass()); assertSame(c4, grid.getComponent(2, 1)); assertSame(c5, grid.getComponent(2, 2)); assertSame(c6, grid.getComponent(2, 3)); }