I'm working with a JFrame
adding JPanel
instances dynamically in the following way:
private void addBox(int x, int y){
JPanel panel = new JPanel();
panel.setBackground(Color.RED);
panel.setSize(10, 10);
panel.setVisible(true);
panel.setLocation(x, y);
this.getContentPane().add(panel);
}
The problem is, when I use addBox
method, the JPanel
instance does not appear in the JFrame
. The only way I can see the box I need to manualy resize the window.
Note: I tried using this.pack();
, but this did not work.