I have the following code, but my JPanel just doesn’t show. I can’t figure out why. Do you see why? All I see is the JFrame with black background
public class ShapeFrame extends JFrame
{
private JPanel outlinePanel;
public ShapeFrame(LinkedList<Coordinate> list)
{
super("Outline / Abstract Image");
setSize(950, 500);
setLayout(null);
setBackground(Color.BLACK);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
JPanel outlinePanel = new JPanel();
outlinePanel.setBackground(Color.WHITE);
outlinePanel.setBorder(null);
outlinePanel.setBounds(50, 50, 400, 400);
add(outlinePanel);
// abstractPanel = new JPanel();
// abstractPanel.setBackground(Color.WHITE);
// abstractPanel.setBounds(500, 50, 400, 400);
// add(abstractPanel);
}
All I get is a frame with a white square in it…
You should use
getContentPane().setBackground()to set the back ground of the frameFrames are made up of layers. Typically, the content that you see is added (automatically in most cases) to the content pane, which covers the frame.
(Picture borrowed from the Java Trails)
So setting the background of the frame “appears” to have no effect.
Using your code…
Using
getContent().setBackground(...)This is the code I used to test your code with…