Finally it's done to make rounded corners for JButton, i'm tired to remove the edges that show after border radius without using transparent images
Screenshot of JButton
here's the code
JButton button = new JButton("SIGN IN");
Color borderColor = Color.decode("#2c3338");
button.setBorder(new RoundedBorder(20, borderColor));
button.setFont(new Font("SansSerif", Font.BOLD, 11));
button.setBackground(Color.decode("#ea4c88"));
button.setForeground(Color.WHITE);
button.setFocusPainted(false);
button.setContentAreaFilled(false);
button.setOpaque(true);
button.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
button.setBounds(135, 233, 280, 44);
container.add(button);
public class RoundedBorder implements Border {
private int radius;
private Color borderColor;
public RoundedBorder(int Radius, Color BorderColor) {
radius = Radius;
borderColor = BorderColor;
}
public Insets getBorderInsets(Component c) {
return new Insets(radius, radius, radius, radius);
}
public boolean isBorderOpaque() {
return true;
}
public void paintBorder(Component c, Graphics Graphics, int x, int y, int width, int height) {
Graphics2D Graphics2D = (Graphics2D) Graphics.create();
Graphics2D.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
Graphics2D.setColor(borderColor);
Graphics2D.setStroke(new BasicStroke(2));
Graphics2D.drawRoundRect(x, y, width - 1, height - 1, radius, radius);
Graphics2D.dispose();
}
}

Borderisn't meant to "fill" and based on the order of the paint chain, it's called AFTER the background is painted.A possible solution is to "fake" it instead, for example...
Please also note, the simple use of
GridBagLayoutin the example, which deals with calculating the size and position of the button, the addition of theiPadxconstraint to increase the width of the button and obviously, the overriddengetInsetsmethod of theJButton.Also not the order in which the button is painted, you MUST paint the background BEFORE calling
super.paintComponent, as the super method will paint the textButton corners don't get painted over by borders, they are moved outwards instead demonstrates an alternative which can be used to change ANY (or all)
JButton, rather then needing to use a dedicate class. This example simple creates a newButtonUIwhich can be applied to ANY instance ofJButtonto change the way in which it's painted, arguably making it a better solution where you already have a pre-existing UI.