JPanel doesn't update when adding Component in another class

前端 未结 3 588
甜味超标
甜味超标 2020-11-29 13:43

I\'m fairly new to Java Swing and I\'m running into a few problems.

  1. As a side question, when making a fairly large Java Swing Application, what is the best wa
3条回答
  •  清歌不尽
    2020-11-29 14:21

    You should revalidate your panel

    @Override
    public void actionPerformed(ActionEvent e) {
       JButton temp = new JButton("temp");
       mPanel.add(temp);
       mPanel.revalidate();
       mPanel.repaint();
    }
    

提交回复
热议问题