• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

not so simple question about swing

 
Bilal Ali
Ranch Hand
Posts: 66
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Rancher
Posts: 42968
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 66
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 14112
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Brian Cole
Author
Ranch Hand
Posts: 908
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic