1

我有两个JPanels:a1a2. a11是 的子面板a1。我想a11搬到a2. 这个怎么做?

4

2 回答 2

4

Try this:

a2.add(a11); // move a11 from a1 to a2
a2.revalidate(); // apply changes in a2 layout
a1.revalidate(); // apply changes in a1 layout
a2.repaint(); // repaint a2 you to be able to see the changes
a1.repaint(); // repaint a1 you to be able to see the changes
于 2013-06-20T11:44:00.563 回答
3

您可以先从 a1 中删除 a11,然后将其添加到 a2。

如下,

a1.remove(a11);
a2.add(a11);
a2.repaint();

于 2013-06-20T11:47:04.630 回答