public void renderPanels(){
for(int i = 1; i<4; i++){
for(int j = 1; j<4; j++){
panels[i][j] = new JPanel();
frame.add(panels[i][j]);
buttons[i][j] = new JButton();
panels[i][j].add(buttons[i][j]);
panels[i][j].setBounds(i*50, j*50, 50, 50);
panels[i][j].setLayout(null);
buttons[i][j].setBounds(0, 0, 50, 50);
System.out.println(panels[i][j].getBounds());
}
}
}
Ok so this is my code to render a 3x3 grid of panels with buttons inside them. the frame variable contains a JFrame
object but sadly my output is like in the following screenshot:
the frame in the last iteration seems to be rendered at a location as if i and j are 1 unit below the initial values. Any Ideas?