i have a database that i build a table from, getting the columns n then the rows to populate this.

i have
Java Code:
        HDTable.setAutoCreateRowSorter(true);
and this works on sorting the columns by the header.

i also have
Java Code:
 HDTable.getSelectionModel().addListSelectionListener(new ListSelectionListener() {

            public void valueChanged(ListSelectionEvent e) {
                //retrieving the selected row index
                int row = HDTable.getSelectedRow();
                String model, site, server;
                model = HDTable.getValueAt(row, 0).toString();
                HDdisklabelTb.setText(model);
                model = HDTable.getValueAt(row, 1).toString();
                HDserialTb.setText(model);
                model = HDTable.getValueAt(row, 2).toString();
                HDsizeTb.setText(model);
                model = HDTable.getValueAt(row, 3).toString();
                HDcommentsTb.setText(model);
so that when the user clicks on a row the data is put into text boxes.

but when you click a row and then sort the column by clicking on the header, i get a comile time error of
XML Code:
ArrayIndexOutOfBounds
how do I stop the error?
how can i check if the user has clicked on a row or column.

also how do i set the table to not editable be still enabled.
im using netbeans SE to design this.

Thanks