问题描述
如何在jpanel中动态添加组件?
当我点击按钮时,我有添加按钮,组件应该添加到JPanel。
how can i add components dynamically in a jpanel?I am having add button when i click the button the components should be added to the JPanel.
我的问题是当jpanel添加文本字段和按钮时我点击添加按钮,用户可以根据我必须将其添加到jpanel的任意次数点击添加按钮。我已经将scrollerpane添加到我的jpanel,并且jpanel布局管理器设置为null。
my question is that adding a textfield and button to jpanel when i click on the add button the user can click on the add button any number of times according to that i have to add them to the jpanel. i have added to scrollerpane to my jpanel,and jpanel layout manager is set to null.
推荐答案
就像你一直做的那样,除了您必须致电:
Just as you always do, except that you have to call:
panel.revalidate();
完成后,因为容器已经实现。
when you are done, since the container is already realized.
这篇关于在JPanel中动态添加组件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!