Win a copy of Cross-Platform Desktop Applications: Using Node, Electron, and NW.js this week in the JavaScript forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Get cell values of a JTable row.  RSS feed

 
Bruce Jin
Ranch Hand
Posts: 672
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I want to get all cell values of a row (that was clicked) when I click a button outside the table. How to do this?
I have an action listener for this button. In the actionPerformed() method I have access to the table object.
Thanks.
 
Nathan Pruett
Bartender
Posts: 4121
IntelliJ IDE Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Something like this should work...


Of course, you can replace the array with a Vector, ArrayList, Hashtable, etc.
[ December 21, 2002: Message edited by: Nathan Pruett ]
 
Bruce Jin
Ranch Hand
Posts: 672
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks alot!
 
Kevin Ng
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Dear Nathan Pruett,
Normally if we want to delete a particuler record in databasee which is by clicking a button in my application but i want to delete a particular record by clicking the entire row of JTable. The problem is how the system know which record in database i wish to delete by just click on the entire row? How should the code will liik like.
Thank you in advance!
 
Stuart Friedberg
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Kevin,
JTable doesn't "understand" your database. You must include in the JTable (or the underlying TableModel) sufficient information to identify the row in your database. This may be the key column value(s) for the database table, a rowid, or whatever you plan to use in your database delete statement. When someone clicks on a JTable row, it's up to your Java code to retrieve the information identifying the row (from the TableModel) and use it in the delete statement.
You don't have to display that information in the JTable, of course. You can have lots of columns in a TableModel that are not display in the JTable.
 
Don't get me started about those stupid light bulbs.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!