Grid extends JPanel implements GridSelectionModel.Listener { public void setHeaderRow(JComponent... components) { checkColumnCount(components); List<JComponent> headerRow = new ArrayList<>(components.length + 1); AbstractButton headerRowSelector = createHeaderRowSelector(); if (headerRowSelector != null) { headerRowSelector.setVisible(showSelectionColumn); headerRowSelector.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { onHeaderRowSelectorAction(); } }); } headerRow.add(headerRowSelector); Collections.addAll(headerRow, components); addComponentRowIntern(headerRow, 0); componentRows.set(0, headerRow); 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 testSetHeaderRow() throws Exception { Grid grid = new Grid(4, true); JLabel c1 = new JLabel(); JLabel c2 = new JLabel(); JLabel c3 = new JLabel(); grid.setHeaderRow(c1, c2, c3); assertEquals(4, grid.getColumnCount()); assertEquals(0, grid.getDataRowCount()); assertEquals(1, grid.getRowCount()); assertNotNull(grid.getComponent(0, 0)); assertEquals(JCheckBox.class, grid.getComponent(0, 0).getClass()); assertSame(c1, grid.getComponent(0, 1)); assertSame(c2, grid.getComponent(0, 2)); assertSame(c3, grid.getComponent(0, 3)); }