remover fondo inusual detras de textfield
AUTOR PREGUNTA #1
used class to make rounded border
the class is :
public class RoundedBorder implements Border {
int radius;
public RoundedBorder(int radius) {
this.radius = radius; }
@Override
public Insets getBorderInsets(Component c) {
return new Insets(this.radius/2, this.radius, this.radius/2, this.radius); } @Override
public boolean isBorderOpaque() {
return true; }
@Override
public void paintBorder(Component c, Graphics g, int x, int y, int width, int height) {
Graphics2D graphics = (Graphics2D) g; graphics.setRenderingHint(RenderingHints.KEY_ANTIALIASING,RenderingHints.VALUE_ANTIALIAS_ON);
g.drawRoundRect(x,y,width-1,height-1,radius,radius); } }
Y para el campo de texto el siguiente codigo donde uso Jtextfield:
JTextField usuario= new JTextField(); usuario.setBorder(new RoundedBorder(10)); usuario.setPreferredSize(new Dimension(150, 25));
Y funciona de maravilla, pero al momento de generarse el campo un fondo inusual se coloca detras de mi campo de texto especificamente en los bordes, les dejo una imagen para ilustrar mejor:
Gracias de antemano
-
¿Tienes la misma pregunta? Yo también
Esto también te interesa!
PREGUNTAS SIMILARES
#2
#3
@Override
public void paintBorder(Component c, Graphics g, int x, int y, int width, int height) {
Graphics2D graphics = (Graphics2D) g; graphics.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
if (c.getParent() != null) {
Color bc = g.getColor(); g.setColor(c.getParent().getBackground());
for (int r = 0; r<radius;r++){
g.drawRoundRect(x, y, width - 1, height - 1, r, r); } g.setColor(bc); } g.drawRoundRect(x, y, width - 1, height - 1, radius, radius); }