I am currently trying to make rounded JPanels that are colored, but whenever I set the background, I get an issue. The color is leaking through the border, and I am unsure of how to fix this. I am relatively new to java, and any help would be appreciated. Thanks!
Image of issue:
My code:
import java.awt.*;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import javax.swing.*;
import javax.swing.border.Border;
public class Main extends JPanel {
public static void main(String[] args) {
JFrame home = new JFrame();
home.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
home.setLayout(null);
home.setSize(1000, 700);
home.setLocation(400, 150);
home.getContentPane().setBackground(new Color(30, 50, 70));
home.setResizable(false);
//UPPER PANEL
JPanel upper = new JPanel();
upper.setBackground(new Color(100, 50, 75));
upper.setBounds(20, 20, 960, 100);
upper.setBorder(new RoundedBorder(30));
//LOWER LEFT PANEL
JPanel ll = new JPanel();
ll.setBackground(new Color(100, 50, 75));
ll.setBounds(20, 140, 660, 500);
ll.setBorder(new RoundedBorder(30));
//LOWER RIGHT PANEL
JPanel lr = new JPanel();
lr.setBackground(new Color(100, 50, 75));
lr.setBounds(700, 140, 280, 500);
lr.setBorder(new RoundedBorder(30));
home.add(ll);
home.add(lr);
home.add(upper);
home.setVisible(true);
}
private static class RoundedBorder implements Border {
private int radius;
RoundedBorder(int radius) {
this.radius = radius;
}
@Override
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);
}
@Override
public Insets getBorderInsets(Component c) {
return new Insets(this.radius + 1, this.radius + 1, this.radius + 2, this.radius);
}
@Override
public boolean isBorderOpaque() {
return false;
}
}
}
I have tried looking at things about rounded rectangles, but I'm not even sure if I was on the right track.