Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Java > rollover effect on a button?

Thread Tools

rollover effect on a button?

Posts: n/a

I want a border appears when I roll over with the mouse over a button.
And when I quit the button area the border should be disappeared. At
first I resolved the problem by setting a LineBorder in the
mouseEntered method and setting an EmptyBorder in the mouseExited
method. However the border is drawed around the hole button. But I
want only the icon at the button surrounded by a border. Therefore I
tried to resolve it in another way which is show in the following
class myButton:

public class myButton extends JButton {

private boolean isOver = false;
int iconHeight, iconWidth;

public myButton(String s, ImageIcon icon) {
super(s, icon);
iconWidth = icon.getIconWidth();
iconHeight = icon.getIconHeight();


addMouseListener(new MouseAdapter() {

public void mouseEntered(MouseEvent e) {
isOver = true;

public void mouseExited(MouseEvent e) {
isOver = false;


public void paint(Graphics g) {

if(isOver) {

g.drawRect(	getX() + getInsets().left,
getY() + getInsets().top,


Much to my surprise I found that only the first used instance of the
class myButton shows the implemented behaviour. All afterwards
instanced objects of myButton seem to be without the new extended
paint method. But why? I would be very grateful if you could test the
myButton class and post your experience.

Reply With Quote
Bjorn Abelli
Posts: n/a

"Sandro" wrote this to c.l.j.h. as well...

Please don't multi-post.

You can read my answer to your post in

// Bjorn A

Reply With Quote
Andrew Thompson
Posts: n/a
On Fri, 14 Jan 2005 23:32:30 +0100, Bjorn Abelli wrote:

> "Sandro" wrote this to c.l.j.h. as well...
> Please don't multi-post.
> You can read my answer to your post in

Or my response in c.l.j.gui referring the OP back to it, or..??

I hope, Sandro, that you now understand why people dislike
multi-posting so much.

Andrew Thompson Web & IT Help Open-source software suite Science & Technology Images that escape the mundane
Reply With Quote

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
problem creating css rollover effect! Jeff ASP .Net 1 03-21-2009 11:44 PM
Simple Rollover Menu effect Els HTML 2 04-01-2007 09:45 PM
rollover effect Sorin Schwimmer Python 0 08-28-2006 02:57 PM
rollover effect groves Python 13 08-26-2006 11:45 PM
Floating menu with disjointed rollover effect Javascript 0 06-15-2006 03:38 PM