?
Solved

Using a TAB to move around a JTable

Posted on 1998-11-05
2
Medium Priority
?
441 Views
Last Modified: 2008-02-01
What would be the easiest way to use the TAB key to move around the cells in a JTable?  Pressing TAB will call the Swing Focus Manager to transfer focus out of the table instead of shifting to the next cell.  Listening for key strokes in this case will not work since the Focus Manager gets the first report of the TAB key and consumes it.
0
Comment
Question by:darrenc
[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
2 Comments
 
LVL 2

Accepted Solution

by:
mwibbels earned 400 total points
ID: 1227001
The first step is to overload the 'isManagingFocus()' method of the JTable, to let the Focus Manager know that you do your own managing:

    public boolean isManagingFocus() {
        return true;
    }

this way the FocusManager will ignore TAB keys when your component (JTable) has the focus.

The second step would probably be to look in the BasicTableUI source, and create your own TableUI that reacts to TAB presses the way you want. You can see there what happens whenever VK_UP, VK_LEFT, etc. is pressed. That is quite similar to what you want.

I once tried listening to KeyEvents from the JTable, but a keyPressed is the sign for the table to start a cell editor (this is done in the TableUI), so if you allow your cells to be edited this will not work.

0
 

Author Comment

by:darrenc
ID: 1227002
Thanks mwibbles!!  Didn't know about the TableUI stuff (BTW If you know of a link that explains TableUI well that would be terrific).

I might just add listeners to both the JTable and the actual editors (text fields in my case - set column editor to be new DefaultCellEditor(JTextField)).  Sounds easier but I'll have to have a look into the TableUI.
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Introduction This article is the first of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article explains our test automation goals. Then rationale is given for the tools we use to a…
Introduction This article is the second of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers the basic installation and configuration of the test automation tools used by…
Viewers will learn one way to get user input in Java. Introduce the Scanner object: Declare the variable that stores the user input: An example prompting the user for input: Methods you need to invoke in order to properly get  user input:
The viewer will learn how to implement Singleton Design Pattern in Java.
Suggested Courses
Course of the Month11 days, 20 hours left to enroll

752 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