S
Sandro
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:
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
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