编辑面板后将面板读取到布局?
我想做的是动态编辑面板并将其重新添加到(边框)布局中。该面板包含文本字段,我希望用户能够向面板添加或删除文本字段。我尝试的是以下内容:从布局中删除面板,将另一个文本字段添加到面板中,将面板重新添加到布局中。然而,这不起作用(什么也没发生;只是面板被删除,但没有用其中的新文本字段读取,所以该区域只是空的)。即使我从布局中删除面板,然后在该位置(BorderLayout.EAST)的布局中添加另一个组件;什么也没发生(只是空的)。
这是代码中不起作用的部分:
vfields[blocks] = new TextField("0"); //add new textfield to the array of textfields
blocks += 1;
dp.blocks = blocks;
this.remove(values_fields); //remove the values_fields panel from the borderlayout
values_fields.add(vfields[blocks]); //add new component,textfield to the panel
this.add(values_fields, BorderLayout.EAST); //readd the panel to the border layout<-- doesn't work
我希望任何人都可以帮助我。我对 Java 还比较陌生,所以我可能只是做了一些完全错误的事情,但我自己并没有看到这一点。
提前致谢!
斯凯夫。
What I'm trying to do is dynamicly edit a panel and readd it to the (Border)layout. The panel contains textfields and I want the user to be able to add or remove textfields to the panel. What I tried is the following: remove the panel from the layout, add another textfield to the panel, readd the panel to the layout. However this doesn't work ( nothing happened; only the panel was removed but not readded with the new textfield in it , so the area was just empty ). Even when I removed the panel from the layout and then added another component to the layout at that position (BorderLayout.EAST) instead; nothing happened ( just empty ).
This is the part of the code which is not working:
vfields[blocks] = new TextField("0"); //add new textfield to the array of textfields
blocks += 1;
dp.blocks = blocks;
this.remove(values_fields); //remove the values_fields panel from the borderlayout
values_fields.add(vfields[blocks]); //add new component,textfield to the panel
this.add(values_fields, BorderLayout.EAST); //readd the panel to the border layout<-- doesn't work
I hope anyone can help me out. I'm relative new to Java so I might just be doing something totally wrong or something, but I don't see it myself.
Thanks in advance!
Skyfe.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
无需拆除整个面板。您只需删除/添加组件到现有面板即可。在可见的 GUI 上,代码的顺序为:
如果您需要更多帮助,请发布您的 SSCCE。
There is no need to remove the entire panel. You can just remove/add components to the existing panel. On a visible GUI the order of the code would be:
If you need more help post your SSCCE.
看起来它不会再重新粉刷了。
您是否尝试过在gui更改后调用以下两个方法:
It looks like it doesnt get repaint again.
Have you tried to call the following two methods after the gui changes: