John Murano John Murano - 2 months ago 12
Java Question

How to focus a JFrame?

I am writing a small game, with one JFrame that holds the main game, and another JFrame that displays the score. the problem is, when I am done constructing them, the score JFrame always ends up focused! I have tried calling scoreDisplay.toFront(), scoreDisplay.requestFocus(), and even:


Is there any way to make this work?
Thanks in advance,
john murano


Have you consider setting the score in the same frame as the game frame?

Other possible ( quick and dirty ) option is to create them in reverse order, or at least ( if score depends on game ) display them in reverse order.

score.setVisible( true );
game.setVisible( true );

My guess is that currently they are:

game.setVisible( true );
score.setVisible( true );