• Post Reply Bookmark Topic Watch Topic
  • New Topic

setSelectedItem for JTable  RSS feed

 
Manoj Tyagi
Ranch Hand
Posts: 35
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am working on JTable, showing 2 fields - Mobile no & Status. Status field is editable. Now my problem is that , i have to provide a search for mobile no.(having 5000 mobile nos.). I want that on search, requested mobile no(row) should be shown as selected. But in JTable methods, i have not found any method to set this.
For table model, i am simply extending AbstractModel class.
Please help me out.
Manoj Tyagi
 
Michael Morris
Ranch Hand
Posts: 3451
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Manoj,
There is a protected field in the JTable class named selectionModel, which is the ListSelectionModel for the JTable. I think you will find the methods there to accomplish your task.
Hope this helps,
Michael Morris
 
Manoj Tyagi
Ranch Hand
Posts: 35
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
Michael Morris
Thanks for your reply, but my problem is not solved. I have tried ListSelectionModel, but this interface does not have any specific method to show(put) particular row as selected one(selecton means, that particular row should be visible with blue foreground, which is by default). Though, i have tried setLeadSelectionIndex & setAnchorSelectionIndex, but nothing seems to be happened.
Please suggest if anything possible
Manoj Tyagi
 
Chantal Ackermann
Ranch Hand
Posts: 508
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
try myTable.setRowSelectionInterval(myRow,myRow).
you will then need to make sure, that it is in the visible range of the scrollpane:

cheers
 
Manoj Tyagi
Ranch Hand
Posts: 35
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi
Chantal
and Michael
Thanks for helping me out. My problem is solved with setSelectionInterval(index,index) method of ListSelectionInterface.
However, chantal as you discussed about the visible range of scrollpane, that problem still persists because i am not able to take the reference of scrollpane in my action performed (because i have made scrollpane as a local method variable, however myTable is a class variable).
Please suggest if anything can be done.
Manoj Tyagi
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!