Select an entire row - JTable Java

1

When I click on the checkbox, only the cell where the checkbox is is selected, as I do so that the entire row is selected at the moment that I select the checkbox. This is my Render class.

public class Mirender extends DefaultTableCellRenderer {

    @Override
    public Component getTableCellRendererComponent(
            JTable table,
            Object value,
            boolean isSelected,
            boolean hasFocus,
            int row,
            int column)
    {
    super.getTableCellRendererComponent (table, value, isSelected, hasFocus, row, column);

    //Alinear al centro los valores de una fila del JTable
    setHorizontalAlignment(SwingConstants.CENTER);

    return this;
    }
} 
    
asked by Bruno 10.01.2017 в 18:22
source

1 answer

2

To start you have to allow selection of rows and prohibit selection of columns with:

table.setRowSelectionAllowed(true);
table.setColumnSelectionAllowed(false);

You can access the selected rows with

int[] selected = table.getSelectedRows();
    
answered by 10.01.2017 / 18:57
source