I am working on a project, in which I need to to change the style of JTextFields
. I extended the BasicTextFieldUI
, and overriden the paintSafely
method, but, when it draws the component, it draws a border (even if the border is setted to null
). I've tryed to look inside the BasicTextUI
class, to see what could draw that border, and I didn't find anything.
Question,
Why will this code create a border around components?
This is my code:
public class CustomTextField extends BasicTextFieldUI{
int borderThickness, edgeRoundness;
@Override
protected void paintSafely(Graphics g) {
JComponent c = (JComponent)this.getComponent();
Graphics2D g2 = (Graphics2D)g;
g2.setColor(c.getBackground());
borderThickness = 2;
edgeRoundness = 20;
g2.setColor(c.getForeground());
g2.fillRoundRect(0, 0, c.getWidth(), c.getHeight(), edgeRoundness+5, edgeRoundness+5);
g2.drawRoundRect(0, 0, c.getWidth(), c.getHeight(), edgeRoundness+5, edgeRoundness+5);
g2.setColor(c.getBackground());
g2.fillRoundRect(borderThickness, borderThickness, c.getWidth()-(int)(borderThickness*2.5), c.getHeight()-(int)(borderThickness*2.5), edgeRoundness, edgeRoundness);
g2.drawRoundRect(borderThickness, borderThickness, c.getWidth()-(int)(borderThickness*2.5), c.getHeight()-(int)(borderThickness*2.5), edgeRoundness, edgeRoundness);
super.paintSafely(g);
}
}
What could be the mistake? Is there any other method used to paint the component?