You need to call
aPanel.revalidate();
before invoking repaint()
.
Side note: Take a look at CardLayout
for changing the visibility of components at runtime
Domanda
I have empty jpanel. After button click should add elements to it in loop. My code:
radio = new JRadioButton[answerArrayList.size()];
for (int i = 0; i < answerArrayList.size(); i++) {
final Answer a = answerArrayList.get(i);
radio[i] = new JRadioButton();
radio[i].setText(a.getAnswer());
group.add(radio[i]);
aPanel.add(radio[i]);
}
aPanel.repaint();
But after this action panel is still empty. How I can add items to panel and clear all items from it?
Soluzione
You need to call
aPanel.revalidate();
before invoking repaint()
.
Side note: Take a look at CardLayout
for changing the visibility of components at runtime