1.11M Members

JTable getColumnModel().getSelectionModel

 
0
 
//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();
 
0
 

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.

 
0
 
  • 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

You
This article has been dead for over six months: Start a new discussion instead
Post:
Start New Discussion
Tags Related to this Article