简体   繁体   中英

How to move jpanel to another jpanel in a same jframe

I have a two JPanel s: a1 and a2 . a11 is sub panel of a1 . I want move a11 to a2 . How to do this?

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

you can do that by first remove a11 from a1 and then adding it to a2.

as follows,

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM