My question at this time is whether there is any method or class predefined in java to be able to create a button with round edges.
My question at this time is whether there is any method or class predefined in java to be able to create a button with round edges.
The JButton
actually has round edges, what you can do is increase the radius of the angulo,
as a proposal this class:
import java.awt.Component;
import java.awt.Graphics;
import java.awt.Insets;
import javax.swing.border.Border;
class RoundedBorder implements Border {
private int radius;
RoundedBorder(int radius) {
this.radius = radius;
}
public Insets getBorderInsets(Component c) {
return new Insets(this.radius+1, this.radius+1, this.radius+2, this.radius);
}
public boolean isBorderOpaque() {
return true;
}
public void paintBorder(Component c, Graphics g, int x, int y, int width, int height) {
g.drawRoundRect(x, y, width-1, height-1, radius, radius);
}
}
You create your button and define the class with the desired radius in the Border property:
//Crea boton.
JButton myButton = new JButton("my button");
//Define 40 como Radio.
myButton.setBorder(new RoundedBorder(40));