AbstractTableModel: from cell to column and row header

159 Views Asked by At

I have a table that extends AbstractTableModel, I have implemented a method to return the number of column and row of a double-clicked cell (in this way I can individuate univocally the cell in question). I would like to have the column and the row header (row header= the text in first cell of every row) of a cell such determined. Here the code for cell individuation:

table= new JTable(new MyTableModel());
table.addMouseListener(new MouseAdapter(){
        public void mouseClicked(MouseEvent e) {
            if (e.getClickCount() > 1) {
              int row = table.rowAtPoint(new Point(e.getX(), e.getY()));
              int col = table.columnAtPoint(new Point(e.getX(), e.getY()));

                }
              }
    });
private class MyTableModel extends AbstractTableModel {...}

Found the solution for column's name:

System.out.println(table.getColumnName(col));

Now we have to resolve for the rows.

And...Found the solution for rows:

System.out.println(table.getValueAt(row, 0));

"thank you" for my own help.. Wish that will be useful for others readers

0

There are 0 best solutions below