0

I have this table model and I want to get Checkboxes in the first column. How can I do this? Do I have to make an extra column in my table?

ResultSetMetaData metaData = rs.getMetaData();


        int numberOfColumns = metaData.getColumnCount();
        Vector<String> columnNames = new Vector<String>();

        for (int column = 0; column < numberOfColumns; column++) {
            columnNames.addElement(metaData.getColumnLabel(column + 1));
        }

        rows = new Vector<Vector<Object>>();

        while (rs.next()) {
            Vector<Object> newRow = new Vector<Object>();

            for (int i = 1; i <= numberOfColumns; i++) {
                newRow.addElement(rs.getObject(i));
                }

            rows.addElement(newRow);
            }

        return new DefaultTableModel(rows, columnNames);

I already tried this. It is working, but I don't want to make an extra column in my table and I also want to have a Checkbox on the top which selects all other ons. Does anyone knows how it works?

table.getColumn("Select").setCellRenderer(
                  table.getDefaultRenderer(Boolean.class));
coo12
  • 117
  • 1
  • 11
  • possible duplicate of [How do I add a JCheckBox to DefaultTableModel by adding a Boolean column?](http://stackoverflow.com/questions/13690488/how-do-i-add-a-jcheckbox-to-defaulttablemodel-by-adding-a-boolean-column) – DavidPostill Aug 26 '14 at 09:20
  • No, i want to add checkbox without adding an extra column in my table. I am getting the data from a mySQL table. – coo12 Aug 26 '14 at 09:34
  • Read it again carefully. The question and answer explain how to "automatically returns a checkbox for you if you render a Boolean.class in a column" – DavidPostill Aug 26 '14 at 09:36
  • See http://www.java2s.com/Tutorial/Java/0240__Swing/UsingdefaultBooleanvaluecelleditorandrenderer.htm for a simple example – DavidPostill Aug 26 '14 at 09:41

0 Answers0