[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

Processing a TAB KeyEvent

Posted on 2004-09-05
6
Medium Priority
?
1,329 Views
Last Modified: 2012-08-13
Hey Experts,

I wanted to programmatically process a TAB KeyEvent at a certain part of a program (as if the user has pressed the TAB Key). I wrote the following piece of code:

DefaultFocusManager fm = new DefaultFocusManager();
fm.processKeyEvent(jtablex,KeyEvent.VK_TAB); //where jtablex is a Component

The problem with this code was that KeyEvent.VK_TAB is an integer not a KeyEvent object (and there is no overloaded function that takes a component and a KeyEvent object).What do I do to process this KeyEvent?
0
Comment
Question by:mte01
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
6 Comments
 
LVL 86

Assisted Solution

by:CEHJ
CEHJ earned 1080 total points
ID: 11983664
Try

EventQueue.postEvent(new KeyEvent(......................));

and see

http://java.sun.com/j2se/1.5.0/docs/api/java/awt/event/KeyEvent.html#KeyEvent(java.awt.Component, int, long, int, int, char)
0
 
LVL 3

Assisted Solution

by:JohnnyAffa
JohnnyAffa earned 920 total points
ID: 11984021
here you go!  

ive simulated the TAB key press by using a thread and tiggering it to act after 3 seconds, after which a message "Wow, how did that happen?" is displayed to the console.  you need to implement the KeyListener interface givent that you want to trigger a key event.

how its want you want ;-)

import java.awt.event.*;
import javax.swing.*;
import java.awt.*;
import javax.swing.event.*;

class TAB extends JFrame implements Runnable, KeyListener
{
      public TAB()
      {
            this.setInterface();
      }

      private void setInterface()
      {
            this.setBounds(50,80,400,400);

            this.setVisible(true);

            (new Thread(this)).start();
      }

      public void keyPressed( KeyEvent e)
      {
            if ( e.getID() == KeyEvent.VK_TAB )
                  System.out.println("Wow, how did that happen?");
      }
 
      public void keyReleased( KeyEvent e)
      {

      }

      public void keyTyped( KeyEvent e)
      {

      }

      public void processWindowEvent(WindowEvent event)
      {
            if ( event.getID() == WindowEvent.WINDOW_CLOSING )
                  System.exit(0);
      }

      public void run()
      {
            try
            {
                  Thread.sleep(3000);
                  this.keyPressed(new KeyEvent(this,KeyEvent.VK_TAB,0,0,0));
            }
            catch (Exception a)
            {

            }
      }

      public static void main(String args[])
      {
            new TAB();
      }
}
0
 
LVL 86

Accepted Solution

by:
CEHJ earned 1080 total points
ID: 11984234
That of course won't act like a 'normal' key event as it's not posted on the event dispatch thread
0
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
LVL 3

Author Comment

by:mte01
ID: 11984379
Thanks for all your support guys, I'll try to award the points as fairly as possible.
0
 
LVL 3

Author Comment

by:mte01
ID: 11984384
I increased the number of points so that you get fairly rewarded
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 11984394
:-)
0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction This article is the last of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers our test design approach and then goes through a simple test case example, how …
In this post we will learn different types of Android Layout and some basics of an Android App.
Viewers learn about the scanner class in this video and are introduced to receiving user input for their programs. Additionally, objects, conditional statements, and loops are used to help reinforce the concepts. Introduce Scanner class: Importing…
Viewers will learn about the different types of variables in Java and how to declare them. Decide the type of variable desired: Put the keyword corresponding to the type of variable in front of the variable name: Use the equal sign to assign a v…
Suggested Courses

656 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question