HunderingThooves
HunderingThooves

Reputation: 992

Swap the screen location of two items in java swing?

I am having a bit of an issue right now. Is there any simple way to swap the positions of two elements in a java swing program.

Example: I have labels label1, and label2.

Label1 is added to the panel with its bounds set (not layout manager) something like this:

label1.setBounds(300,200,150,150);

label 2 is added similarly:

label2.setbounds(500,500,150,150);

Assuming that I wanted to swap the positions of label 1 and label 2, would there be any way to do that? Thanks!

Upvotes: 0

Views: 247

Answers (1)

Tom
Tom

Reputation: 44841

You mean different from:

Rectangle r1 = new Rectangle();
Rectangle r2 = new Rectangle();
label1.getBounds(r1);
label2.getBounds(r2);

label1.setBounds(r2);
label2.setBounds(r1);

Upvotes: 3

Related Questions