user2663778
user2663778

Reputation: 47

Java JFrame to the Front

i actually have problems getting my JFrame to the front when i call it.

I have a class inherting from JDialog. It pops up when i start up my very cool java game. if i now for example want to load a game i press the load button and another JDialog opens to choose the game to load. So i now have to JDialogs open => The startup dialog and the loading dialog. ok, when i chosed a game and loaded it the load jdialog disposes the JFrame for the loaded game appears and after that the startup jdialog comes to the front again.

I dont want the startup dialog to come to the front!

i already added the following codeline to my JFrame for the game:

this.toFront()

without any effect.

How can i get my JFrame to the front?

Upvotes: 0

Views: 1331

Answers (3)

Joseph Pla
Joseph Pla

Reputation: 1598

JDialog objects are supposed to stay on top and will take precedence over any other frames, but if you want to disable that, you can use the following function:

jDialog.setAlwaysOnTop(false);

You can then call the following function on your JFrame:

this.toFront();

Upvotes: 1

Gerret
Gerret

Reputation: 3046

I think you mean that you can't interact with your JFrame anymore because the Dialog blocks it. I dont know now what your startup dialog do, but you could put that into a JPanel or a new JFrame!

If you use

JOptionPane.showMessageDialog();

you can't interact with your JFrame anymore, first you have to close the dialog.

Make a JPanel and a JFrame and put that what you have in the dialog at your JPanel and open the new Frame if you click on the startbutton.

Upvotes: 0

Malwaregeek
Malwaregeek

Reputation: 2274

Well if you are trying to open a JFrame on the click event of load button, you should try the following code on its event handler

JFrame o = new JFrame();
  o.setVisible(true);
  dispose();

Upvotes: 0

Related Questions