每次单击 JList 项目时,我都需要清除 + 刷新当前面板并加载另一个面板,通过方法“populateWithButtons()”返回。temp 是一个 int 变量,用于存储在 JList 中单击的内容。我该如何纠正以下问题?
list_1.addMouseListener(new MouseAdapter() {
@Override
public void mouseClicked(MouseEvent evt) {
//refresh + populate JPanel
Food food = new Food();
JPanel panel2 = new JPanel();
JPanel pane11 = new JPanel();
panel2.add(panel1);
panel1.validate();
panel1.repaint();
panel1.setBounds(153, 74, 281, 269);
panel1.add(food.populateWithButtons(temp));
contentPane.add(panel2);
}