1

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?

enter image description here

Community
  • 1
  • 1
CuriousCI
  • 138
  • 1
  • 11

1 Answers1

1

I found the answe in this post! It seems that, by setting the border to null, I said to the PLAF to use it's own border. Swing JTextField how to remove the border?

CuriousCI
  • 138
  • 1
  • 11