wood burning stoves 2.0*
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


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "not so simple question about swing" Watch "not so simple question about swing" New topic
Author

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
Marshal

Joined: Mar 22, 2005
Posts: 41015
    
  43
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?


Ping & DNS - my free Android networking tools app
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
author
Sheriff

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
Author
Ranch Hand

Joined: Sep 20, 2005
Posts: 862
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

Toolkit.getDefaultToolkit().getSystemEventQueue().push(...);

Then again, I haven't tried it.


bitguru blog
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: not so simple question about swing
 
Similar Threads
Display layer below JComboBox
How do you maximize on frame load?
NullPointerException help....
Focus Lost throws error
jess