We're a community of 1076K IT Pros here for help, advice, solutions, professional growth and fun. Join us!
1,075,752 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Start New Discussion Reply to this Discussion

JTable getColumnModel().getSelectionModel

//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();
3
Contributors
2
Replies
6 Hours
Discussion Span
4 Months Ago
Last Updated
3
Views
cor.vandijk.779
Newbie Poster
5 posts since Jul 2012
Reputation Points: 0
Solved Threads: 0
Skill Endorsements: 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.

JamesCherrill
... trying to help
Moderator
8,507 posts since Apr 2008
Reputation Points: 2,583
Solved Threads: 1,454
Skill Endorsements: 30
  • 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

mKorbel
Nearly a Posting Virtuoso
1,208 posts since Feb 2011
Reputation Points: 482
Solved Threads: 239
Skill Endorsements: 12

This article has been dead for over three months: Start a new discussion instead

Post: Markdown Syntax: Formatting Help
 
You
 
© 2013 DaniWeb® LLC
Page rendered in 0.0625 seconds using 2.74MB