[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

Using a TAB to move around a JTable

Posted on 1998-11-05
2
Medium Priority
?
446 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
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

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

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

In this post we will learn how to make Android Gesture Tutorial and give different functionality whenever a user Touch or Scroll android screen.
Basic understanding on "OO- Object Orientation" is needed for designing a logical solution to solve a problem. Basic OOAD is a prerequisite for a coder to ensure that they follow the basic design of OO. This would help developers to understand the b…
Viewers will learn about arithmetic and Boolean expressions in Java and the logical operators used to create Boolean expressions. We will cover the symbols used for arithmetic expressions and define each logical operator and how to use them in Boole…
Viewers will learn about if statements in Java and their use The if statement: The condition required to create an if statement: Variations of if statements: An example using if statements:
Suggested Courses
Course of the Month19 days, 3 hours left to enroll

834 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