Grid extends JPanel implements GridSelectionModel.Listener { public void addDataRow(JComponent... components) { checkColumnCount(components); removeFiller(); List<JComponent> dataRow = new ArrayList<>(components.length + 1); AbstractButton dataRowSelector = createDataRowSelector(); if (dataRowSelector != null) { dataRowSelector.setVisible(showSelectionColumn); dataRowSelector.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { onDataRowSelectorAction(); } }); } dataRow.add(dataRowSelector); Collections.addAll(dataRow, components); addComponentRowIntern(dataRow, componentRows.size()); componentRows.add(dataRow); addFiller(); fireComponentsChanged(); adjustHeaderRowSelector(); } 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 testAddDataRow() 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); assertEquals(1, grid.getDataRowCount()); assertEquals(2, 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)); grid.addDataRow(c4, c5, c6); 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)); }