• Post Reply Bookmark Topic Watch Topic
  • New Topic

Method for getting row data from a JTable?  RSS feed

 
Marcus Hathaway
Ranch Hand
Posts: 89
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello,

Does anybody know how or of a method that will return the actual row data when selected from a JTable? I've managaed to get the list selection listener working ok. I know this because if i select various rows it will return the row index fine. Is there anyway for it to return the actual row data instead....or perhaps let me say something like....if row 6 is selected, return data for column 3 in a string etc?

I thought a method like getSelectedValue() would work, as this works in a JList, but i guess the JTable is a little more complex! Any help would be greatly appreciated, thank you.
 
Marcus Hathaway
Ranch Hand
Posts: 89
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ok reading Stuarts comment here has solved my problem.

http://www.coderanch.com/t/341086/GUI/java/add-JLabel-JTable-cell
 
Stuart Gray
Ranch Hand
Posts: 410
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You can use the method getValueAt(int row, int col) to return a single cell of data. AFAIK there is no method to get a whole row of data. But if you want to you could grab everything into an array like this:

This is hardcoded to return row zero but you get the idea...
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!