编辑面板后将面板读取到布局?

发布于 2024-09-30 06:30:44 字数 750 浏览 10 评论 0原文

我想做的是动态编辑面板并将其重新添加到(边框)布局中。该面板包含文本字段,我希望用户能够向面板添加或删除文本字段。我尝试的是以下内容:从布局中删除面板,将另一个文本字段添加到面板中,将面板重新添加到布局中。然而,这不起作用(什么也没发生;只是面板被删除,但没有用其中的新文本字段读取,所以该区域只是空的)。即使我从布局中删除面板,然后在该位置(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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

你不是我要的菜∠ 2024-10-07 06:30:44

无需拆除整个面板。您只需删除/添加组件到现有面板即可。在可见的 GUI 上,代码的顺序为:

panel.remove(...);
panel.add(...);
panel.revalidate();
panel.repaint();

如果您需要更多帮助,请发布您的 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:

panel.remove(...);
panel.add(...);
panel.revalidate();
panel.repaint();

If you need more help post your SSCCE.

深海夜未眠 2024-10-07 06:30:44

看起来它不会再重新粉刷了。
您是否尝试过在gui更改后调用以下两个方法:

  validate();
  repaint();

It looks like it doesnt get repaint again.
Have you tried to call the following two methods after the gui changes:

  validate();
  repaint();
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文