-
Update JPanel
Ok, so I have a JPanel full of button inside a JFrame. I want to change where the buttons are. I tried by removing all of the buttons and adding them back in a different order but that didn't work any Ideas? Heres what I tried:
Code:
buttonPanel.removeAll();
for (int i=0; i<9; i++)
{
Buttons[ i ] = new JButton( Names[ i ] );
buttonPanel.add(Buttons[i]);
}
getContentPane().add(buttonPanel);
When I do this, it just hangs.
-
We'll likely need to see more code. A small compilable program that demonstrates your problem would be best.
-
nvm, fixed:
buttonPanel.getRootPane().revalidate();
-
Can't you change the order by adding them individually this way:
Code:
buttonPanel.add(Buttons[0]);
buttonPanel.add(Buttons[5]);
buttonPanel.add(Buttons[1]);
buttonPanel.add(Buttons[4]);
buttonPanel.add(Buttons[8]);
buttonPanel.add(Buttons[6]);
buttonPanel.add(Buttons[2]);
buttonPanel.add(Buttons[3]);
buttonPanel.add(Buttons[1]);