user2504949
user2504949

Reputation: 11

How to move jpanel to another jpanel in a same jframe

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

Upvotes: 1

Views: 629

Answers (2)

SeniorJD
SeniorJD

Reputation: 7212

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

Upvotes: 4

Rahul Borkar
Rahul Borkar

Reputation: 2762

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();

Upvotes: 3

Related Questions