Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

JTable and event listeners

 
Branko Paskutini
Greenhorn
Posts: 25
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi all,
I have added MouseListener and KeyListerner to JTable, used their Adapter classes and implemented keyReleased() and mouseClicked() methods. I have noticed, quite by accident, that the listeners do not always respond to these events. I would say 9 times out of 10 it is working fine and I am getting the correct record, but the 10th time I have a problem. One record is selected (clicked on and it's colour changes to purple), but the application thinks the previous record is selected, and makes booking on that record? This is pretty major. I did some more testing, and sure enough, it might be 1 in 10, it might be 1 in 20, but it happens. JTable responds by changing the colour, but the listeners don't pick it up.
Has anyone else noticed this?? Please let me know.
Thanks, Branko.
 
Pallav Grigo
Greenhorn
Posts: 29
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi..maybe there's something wrong in you mouse listener..how are you detecting the selected row??
this is wut i got..
public void mouseClicked(MouseEvent e) {
if (e.getClickCount() > 1) {
bookFlight(searchTable.getSelectedRow());
}
}
regards,
pallav.
 
Branko Paskutini
Greenhorn
Posts: 25
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Pallav, thank you for your reply. My listener is just like yours, except I don't have "e.getClickCount() > 1". The annoying thing is that it is working 90%-95% of the time, so it's not easy to detect it. The best way to test this is to add println statement to the mouseClicked(), then get all 24 records in JTable, and start clicking.
Since I didn't hear back from anyone I started suspecting it might be something in my code if no one else has experienced it. But it's such a simple piece of code, and why is it working 90% of the time??
OK, I think I found it! After adding mousePressed() and mouseReleased(), I was able to reproduce it - after some clicking, it did NOT respond to mouseClicked(), but it DID to mousePressed() and mouseReleased()! I'll do some more testing, but so far these two new methods are responding 100% of the time.
BTW, I am using JDK 1.3.1 under Windows 2000 Professional.
Thanks, Branko
[ May 19, 2002: Message edited by: Branko Paskutini ]
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic