This week's book giveaway is in the OO, Patterns, UML and Refactoring forum.
We're giving away four copies of Refactoring for Software Design Smells: Managing Technical Debt and have Girish Suryanarayana, Ganesh Samarthyam & Tushar Sharma on-line!
See this thread for details.
The moose likes Swing / AWT / SWT and the fly likes not so simple question about swing Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "not so simple question about swing" Watch "not so simple question about swing" New topic

not so simple question about swing

Bilal Ali
Ranch Hand

Joined: Jun 14, 2007
Posts: 66
Respected Members,
In swing if we bind some event to a component or any container for example if I want to bind an event from my JFrame tha it is necessary that the focus should be set on the JFrame while its running, if the focus is not set than the event will not be fired, is it some way that I set my JFrame as setVisible false but still programitically set the focus by setFocusable(true) or by some other means,now my frame is not visible but since focus has been set from within the program so now will the event be fired.

IF NOT than is there any way in swing that my frame is not visible on the screen but still it fires the events on some key stroke.Please give some suggestions and please help me in finding some solution.

Thanking You,
Bilal Ali.
Ulf Dittmer

Joined: Mar 22, 2005
Posts: 42958
Even if this were possible, how could events meaningfully be associated to UI elements if the user doesn't see them? Can you tell us a bit more about the underlying problem you're trying to solve?
Bilal Ali
Ranch Hand

Joined: Jun 14, 2007
Posts: 66
Actually I want to make a program that when ever the computer starts the program also starts running at the back end in the memory like a windows service, when ever the user presses Ctrl-F3 key stroke together than a pop up message will appear on the window,if the user presses some other key stroke it would be ignored and nothing will happen,my program running in windows service would be contiously monitoring the keys,so I thought to "some how" make a JFrame and set its vasiblity to false," than "some how" bind the key press events to this JFrame,than "some how" set the focus to this frame programitically and at last "some how" get the event be fired.
Ilja Preuss

Joined: Jul 11, 2001
Posts: 14112
I don't think your idea would work, because as soon as the user would try to do something, your JFrame would loose focus, anyway.

Speaking more generally, I don't think that what you are trying to accomplish can be done in vanilla Java.

The soul is dyed the color of its thoughts. Think only on those things that are in line with your principles and can bear the light of day. The content of your character is your choice. Day by day, what you do is who you become. Your integrity is your destiny - it is the light that guides your way. - Heraclitus
Brian Cole
Ranch Hand

Joined: Sep 20, 2005
Posts: 875
Originally posted by Ilja Preuss:
Speaking more generally, I don't think that what you are trying to accomplish can be done in vanilla Java.

I'm not sure I would go that far. I don't see the point in trying to use an invisible Frame or Window to catch key presses, but if you want you can replace the entire event queue via


Then again, I haven't tried it.

bitguru blog
I’ve looked at a lot of different solutions, and in my humble opinion Aspose is the way to go. Here’s the link:
subject: not so simple question about swing
It's not a secret anymore!