Velocity Reviews - Computer Hardware Reviews

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

Reply
Thread Tools

rollover effect on a button?

 
 
Sandro
Guest
Posts: n/a
 
      01-14-2005
Hi,

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:

Code:
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();

setBorder(BorderFactory.createLineBorder(Color.blue));
setFocusPainted(false);
setRolloverEnabled(true);

addMouseListener(new MouseAdapter() {

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

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

}

public void paint(Graphics g) {
super.paint(g);

if(isOver) {

g.setColor(Color.blue);
g.drawRect(	getX() + getInsets().left,
getY() + getInsets().top,
iconWidth,
iconHeight);

}

}
}
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.

Thx
 
Reply With Quote
 
 
 
 
Bjorn Abelli
Guest
Posts: n/a
 
      01-14-2005

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

Please don't multi-post.

You can read my answer to your post in comp.lang.java.help.


// Bjorn A


 
Reply With Quote
 
 
 
 
Andrew Thompson
Guest
Posts: n/a
 
      01-14-2005
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 comp.lang.java.help.


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
http://www.PhySci.org/codes/ Web & IT Help
http://www.PhySci.org/ Open-source software suite
http://www.1point1C.org/ Science & Technology
http://www.LensEscapes.com/ Images that escape the mundane
 
Reply With Quote
 
 
 
Reply

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 jonvillalva@gmail.com Javascript 0 06-15-2006 03:38 PM



Advertisments