How to add components to JFrame once it's visible without having to resize it?

前端 未结 3 1109
猫巷女王i
猫巷女王i 2021-01-16 04:10

I have a program where I have a JFrame with a JButton in it. When the user clicks the JButton, all Components of the

3条回答
  •  执念已碎
    2021-01-16 04:39

    For removing (and then, for example, add new JComponents) JComponents from JPanel or from top-level containers you have to call, only once and on the end of the action:

    revalidate();
    repaint();
    

    And if you only resize or change JComponents:

    validate();
    repaint();
    

提交回复
热议问题