aspose file tools*
The moose likes Swing / AWT / SWT and the fly likes How to change the color of the row(JTable) when mouse move over it? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "How to change the color of the row(JTable) when mouse move over it?" Watch "How to change the color of the row(JTable) when mouse move over it?" New topic
Author

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

Vincint Cao
Greenhorn

Joined: Feb 17, 2002
Posts: 3
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

Joined: Sep 28, 2000
Posts: 508
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

Joined: Feb 17, 2002
Posts: 3
Thanks a lot!
Chantal Ackermann
Ranch Hand

Joined: Sep 28, 2000
Posts: 508
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

Joined: Feb 17, 2002
Posts: 3
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
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: How to change the color of the row(JTable) when mouse move over it?