• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • Liutauras Vilda
  • Jeanne Boyarsky
  • paul wheaton
Sheriffs:
  • Ron McLeod
  • Devaka Cooray
  • Henry Wong
Saloon Keepers:
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Tim Moores
  • Mikalai Zaikin
Bartenders:
  • Frits Walraven

not so simple question about swing

 
Ranch Hand
Posts: 66
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Rancher
Posts: 43081
77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
author
Posts: 14112
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Author
Posts: 986
3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
No more fooling around. Read this tiny ad:
Gift giving made easy with the permaculture playing cards
https://coderanch.com/t/777758/Gift-giving-easy-permaculture-playing
reply
    Bookmark Topic Watch Topic
  • New Topic