Hi!
Making a unique button look at the moment, I just started and was testing all the different things I can do when I came across this small problem.
Here is the source code for my button:
import javax.swing.;
import java.awt.;
import java.awt.geom.;
import java.awt.event.;
public class MyButton extends JButton implements MouseListener{
Shape shape;
Color unarmed = Color.white;
Color armed = Color.cyan;
Color border = Color.black;
public MyButton(String label) {
super(label);
setContentAreaFilled(false);
addMouseListener(this);
}
protected void paintComponent(Graphics g) {
if(getModel().isArmed()){
g.setColor(armed);
}
else{
g.setColor(unarmed);
}
g.fillRoundRect(0, 0, getSize().width-1, getSize().height-1,10,10);
super.paintComponent(g);
}
protected void paintBorder(Graphics g) {
g.setColor(border);
g.drawRoundRect(0, 0, getSize().width-1, getSize().height-1,10,10);
}
public boolean contains(int x, int y) {
if (shape == null || !shape.getBounds().equals(getBounds())){
shape = new RoundRectangle2D.Float(0, 0, getWidth(), getHeight(),10,10);
}
return shape.contains(x, y);
}
public void mouseEntered(MouseEvent e){
border = Color.red;
unarmed = Color.lightGray;
setForeground(Color.red);
repaint();
}
public void mouseExited(MouseEvent e){
border = Color.black;
unarmed = Color.white;
setForeground(Color.black);
repaint();
}
public void mouseClicked(MouseEvent e){}
public void mousePressed(MouseEvent e){}
public void mouseReleased(MouseEvent e){}
}
The problem is this, when you click the button it receives focus, which means it gets a small blue box around the text in the button. Can i remove this blue box? Can I replace this box with my own graphics?
Thanks
Simon