开发者

Readding panel to layout after editing panel?

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]); //a开发者_如何学Cdd 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.


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.


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

  validate();
  repaint();
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜