1,105,395 Community Members

JTable getColumnModel().getSelectionModel

Member Avatar
cor.vandijk.779
Newbie Poster
5 posts since Jul 2012
Reputation Points: 0 [?]
Q&As Helped to Solve: 0 [?]
Skill Endorsements: 0 [?]
 
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();
Member Avatar
JamesCherrill
... trying to help
10,380 posts since Apr 2008
Reputation Points: 2,081 [?]
Q&As Helped to Solve: 1,750 [?]
Skill Endorsements: 47 [?]
Moderator
Featured
 
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.

Member Avatar
mKorbel
Nearly a Posting Virtuoso
1,346 posts since Feb 2011
Reputation Points: 274 [?]
Q&As Helped to Solve: 277 [?]
Skill Endorsements: 14 [?]
 
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 three months: Start a new discussion instead
Post:
Start New Discussion
Tags Related to this Article