Focus on JFrame

From: Michael Kragh Pedersen (m_kragh_pedersen_at_hotmail.com)
Date: 03/26/05


Date: Sat, 26 Mar 2005 14:14:56 +0100

How does focus work in Java? Is it the last component made, that as
standard gets focus, when your JFrame is painted?

And how can I set focus on my JFrame, instead of as it is now my JButton?

When I write

requestFocusInWindow();
setVisible(true);

nothing happens. My JButton is still in focus, but with

setVisible(true);
requestFocusInWindow();

my JFrame gets focus, but my JButton disappears from the JFrame, until I
click somewhere in the area, where it is. After that, every time, I
close and run my Java program again, the JButton is visible, but has
focus too :(

Anybody who can tell me, what's going on with this?

Michael K. P.


Quantcast