Skip to Main Content

Java SE (Java Platform, Standard Edition)

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Switching Window Focus

843806Jul 31 2008 — edited Aug 2 2008
I have an always-on-top floating toolbar running while im working
in a native program. Occasionally I need it to grab focus.
My demo code almost works, in that a cursor appears and starts
blinking but when typing occurs it is clear the window focus hasnt changed.
Does this have to be done natively?

edit: toFront() didnt help either. the window flashed in the taskbar but didnt grab focus.
public void start(){

	JTextArea jta = new JTextArea();

	JFrame win = new JFrame();
	win.getContentPane().add(jta, BorderLayout.CENTER);
	win.setAlwaysOnTop(true);
	win.setSize(400, 100);
	win.setLocationRelativeTo(null);
	win.setVisible(true);

	try{
	Thread.sleep(10000);
	win.requestFocus();
	jta.requestFocus();
	win.setLocationRelativeTo(null);
	} catch(Exception e){
	e.printStackTrace();
	}

}
Edited by: TuringPest on Jul 31, 2008 6:54 PM
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Aug 30 2008
Added on Jul 31 2008
8 comments
358 views