Search...
FAQs
Subscribe
Pie
FAQs
Recent topics
Flagged topics
Hot topics
Best topics
Search...
Search within Swing / AWT / SWT
Search Coderanch
Advance search
Google search
Register / Login
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
Jeanne Boyarsky
Ron McLeod
Paul Clapham
Liutauras Vilda
Sheriffs:
paul wheaton
Rob Spoor
Devaka Cooray
Saloon Keepers:
Stephan van Hulst
Tim Holloway
Carey Brown
Frits Walraven
Tim Moores
Bartenders:
Mikalai Zaikin
Forum:
Swing / AWT / SWT
Pressing a key from the code
Manish
Greenhorn
Posts: 5
posted 22 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
I want to press a Tab Key using my code
Any Help ?
Manfred Leonhardt
Ranch Hand
Posts: 1492
posted 22 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
Hi Prakshi,
Have a look at the helper class I wrote below. It might be just what you want.
class FakeEvent { public static void fakeActionPerformed( Component c ) { ActionEvent ae = new ActionEvent( c, ActionEvent.ACTION_PERFORMED, "" ); fakeExecute( ae ); } public static void fakeKeyPressed( Component c, int keyCode ) { GregorianCalendar gc = new GregorianCalendar(); KeyEvent ke = new KeyEvent( c, KeyEvent.KEY_PRESSED, ((Date)gc.getTime()).getTime(), // When timeStamp 0, // Modifier keyCode ); fakeExecute( ke ); } private static void fakeExecute( AWTEvent ae ) { Toolkit.getDefaultToolkit().getSystemEventQueue().postEvent( ae ); } };
Enjoy,
Manfred.
Manish
Greenhorn
Posts: 5
posted 22 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
Thanks Manfred it worked
Our first order of business must be this tiny ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
reply
Bookmark Topic
Watch Topic
New Topic
Boost this thread!
Similar Threads
Tabbing Out Of JEditorPane...
event.VK_TAB won't work with KeyListener in JPanel?
JTable focus issue
Regarding Focus
Shortcut key to set focus on JFrame
More...