Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

How to change the color of the row(JTable) when mouse move over it?

 
Vincint Cao
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I can create my own cell renderer to make my table look beautiful. But how to add MouseMotionAdapter into my project to make my table more beautiful?
 
Chantal Ackermann
Ranch Hand
Posts: 508
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi,
try

as you cannot transfer the focus itself programmatically to a particular cell, you either have to use the selection or you have to use a special cell renderer you attach and detach whenever the mouse happens to enter a row or to exit it. I don't know how much this will slow down the table performance.
but as the rollover effect is normally coupled to the selection of a row (most of the time the user will select some row while she is moving with the mouse over the table) - i would use the selection of the table to achieve a rollover effect. if you want to display the rollover in another color than the actual selection, you can change the selection background and foreground on the fly. I did that for highlighting search results and differentiate them from user selections. the drawback is that you cannot have different selection colors at the same time.
chantal
 
Vincint Cao
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks a lot!
 
Chantal Ackermann
Ranch Hand
Posts: 508
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi again,
I just realized that the code makes not sense, well, part of the code at least:

this is of course not necessary. you can skip the else-clause.
i found a page about implementing a rollover effect for jtable:
http://www.experts-exchange.com/Programming/Programming_Languages/Java/Q_20227951.html
cheers,
chantal
 
Vincint Cao
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
Your code snippet does help!
However, when mouse moves over one specific row, instead of changing the color only, the row has been selected(This lost lots of conveniences).
I've also browsed the url you recommanded.
If adding such little a function costs so much, I'll give up it.
Thanks anyway!
Best Regards,
Vincint
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic