我有空的jpanel。单击按钮后,应在循环中向其添加元素。我的代码:
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();
但是此动作面板仍然是空的。如何向面板添加项目并清除其中的所有项目?