RuneRebellion
RuneRebellion

Reputation: 149

How to find out where a window is located on a desktop with swing

I'm trying to make a swing application that whenever you click a button it transfers from one jframe to another seamlessly.

This is what code I'm using currently to hide one jframe and display the other

private void switch() {
    this.setVisible(false);
    new Register().setVisible(true);
}

NOW HERE'S THE PROBLEM: lets say the person drags the window to the center of the screen, whenever the above method is called the register jframe would open on the left hand corner, and the current open jframe would hide itself. How would I make it open where the previous jframe was. Also if there is a better way to do what I'm attempting please inform me.

Upvotes: 2

Views: 85

Answers (1)

Salah
Salah

Reputation: 8657

You could use in the second JFrame:

setLocationRelativeTo(firstJFrame);

Or you could use

setLocation(firstJFrame.getLocation());

Upvotes: 2

Related Questions