如何将jpanel移动到同一jframe中的另一个jpanel

时间:2013-06-20 11:38:30

标签: java swing jpanel

我有两个JPanela1a2a11a1的子面板。我希望移动a11a2。 怎么做?

2 个答案:

答案 0 :(得分:4)

试试这个:

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

答案 1 :(得分:3)

你可以先从a1中删除a11然后再添加到a2。

如下,

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