Only 48 hours left in the trailboss' kickstarter!

New rewards and stretch goals. CLICK HERE!



  • Post Reply Bookmark Topic Watch Topic
  • New Topic

question on getSelectionModel() with an abstractTableModel  RSS feed

 
Geoff Jefferson
Ranch Hand
Posts: 102
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have studied the JAVA Tutorial lesson concerning 'How to Write a List Selection Listener' and I can't figure out how to implement the getSelectionModel() method on an abstractTableModel table. I understand that JTable implements this method, but I can't seem to apply this to my model. I think I need to grab a ListSelectionListener event but I can't figure out how.

Thanks.

 
Paul Clapham
Sheriff
Posts: 22185
38
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
When you say
I can't figure out how to implement the getSelectionModel() method on an abstractTableModel table
does that mean you think you have to write an implementation of the selection model? Because normally you'd just use the default selection model associated with the JTable. Or are you asking how to listen for changes in the selection?
 
Geoff Jefferson
Ranch Hand
Posts: 102
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator



>> When you say

>> I can't figure out how to implement the getSelectionModel() method on an abstractTableModel table

>> does that mean you think you have to write an implementation of the selection model? Because normally you'd just use the
>> default selection model associated with the JTable. Or are you asking how to listen for changes in the selection?

I need to listen to changes in the selection.
 
Paul Clapham
Sheriff
Posts: 22185
38
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Okay. So you already know that the getSelectionModel() method returns you the table's ListSelectionModel. Now just add a ListSelectionListener to that.
 
Geoff Jefferson
Ranch Hand
Posts: 102
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Okay. So you already know that the getSelectionModel() method returns you the table's ListSelectionModel. Now just add a ListSelectionListener to that.

That's where I'm running into trouble, and this is probably where I am making my mistake. I am calling the method like this.

I can't get a return from getSelectionModel() because my implementation of the AbstractTableModle doesn't have a method named getSelectionModel(). JTable does, I don't, and I know where to go from here.

 
Rob Spoor
Sheriff
Posts: 20893
81
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Selection is something you do in a view (JTable), not in its backing data model (TableModel). If you would use that TableModel to use in a second JTable (which is perfectly fine), you should still be able to have different selections. If you maintain the selection in the model you can't.
 
Don't get me started about those stupid light bulbs.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!