• Post Reply Bookmark Topic Watch Topic
  • New Topic

Capture Mouse Events on JTable

 
samit naik
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
HI
How do i capture mouse events (such as mouse click) on a single cell in a JTable? Can i capture a mouse click if the cell is non-editable??
ciao
 
Rick Fortier
Ranch Hand
Posts: 147
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I don't the answer but was curious as to why you would need it. On my design I just got the selected row when the user clicked on the Book Flight button.
int rowSelected = table.getSelectedRow()
 
Paul Anilprem
Enthuware Software Support
Ranch Hand
Posts: 3897
12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You can add a MouseListener and MouseMotionListener on the table to capture mouse clicks and mouse moves respectively. From the mouse event you'll get the coordinates and then you may call getRowAt(...) method of JTable to find which row the mouse event happened. Look up the API to see exact method name and parameters.
HTH,
Paul.
------------------
SCJP2 Resources, Free Question A Day, Mock Exam Results and More!
www.jdiscuss.com
Get Certified, Guaranteed!
www.enthuware.com/jqplus

Your guide to SCJD exam!
www.enthuware.com/jdevplus
 
Gravity is a harsh mistress. But this tiny ad is pretty easy to deal with:
the new thread boost feature: great for the advertiser and smooth for the coderanch user
https://coderanch.com/t/674455/Thread-Boost-feature
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!