I have a rounded JButton in my JFrame but it has the sharp corners of which I assume is the default background/border for the JButton itself. I would like to remove that "shaded" tint so that it blends well with the frame color.
For example, I've changed the background color of the button to RED and the corners of the borders are still visible.
Red button with visible background/border
Anyway to go about this?
startButton = new JButton("Start!");
startButton.setPreferredSize(new Dimension(150,80));
startButton.setBorder(new RoundedButton(20));
startButton.setBackground(Color.RED);
startButton.setFont(new Font(null, Font.BOLD, 20));
startButton.addActionListener(this);
class RoundedButton implements Border
{
private int roundRadius;
RoundedButton(int roundRadius)
{
this.roundRadius = roundRadius;
}
public void paintBorder(Component c, Graphics g, int x, int y, int width, int height)
{
g.drawRoundRect(x, y, width-1, height-1, roundRadius, roundRadius);
}
public Insets getBorderInsets(Component c)
{
// TODO Auto-generated method stub
return new Insets(this.roundRadius+1, this.roundRadius+1, this.roundRadius+2, this.roundRadius+2);
}
public boolean isBorderOpaque()
{
return true;
}
}