//Why do I have to use following code to get a column number: 
    ListSelectionModel ks = tabel.getColumnModel().getSelectionModel();
//Rowselection does not require a special row selection, I can get a proper row number with: 
    ListSelectionModel ss = tabel.getSelectionModel();

Remember that columns may be re-ordered relative to the underlying data model. Similarly rows can be sorted and/or filtered before display, in which case to get a row number that refers to the actual row in the data model you need the convertRowIndexToModel method.
Those extra levels of indirection and method calls would be unnecessary for a simple table that just displays the data fully and in the same order, but are needed for the general case where the visible/selectable columns and rows do not correspond directly to the data model.

  • everything depends of JTable.setSelectionMode

  • To retrieve the current selection, use JTable.getSelectedRows which returns an array of row indexes, and JTable.getSelectedColumns which returns an array of column indexes. To retrieve the coordinates of the lead selection, refer to the selection models for the table itself and for the table's column model. The following code formats a string containing the row and column of the lead selection:

    String.format("Lead Selection: %d, %d. ",
    table.getSelectionModel().getLeadSelectionIndex(),
    table.getColumnModel().getSelectionModel().getLeadSelectionIndex());

  • in other hand this is restiction (very bad, disatvantage for JTable) ListSelectionXxx is only one dimensional

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.