Solved

Using a TAB to move around a JTable

Posted on 1998-11-05
2
430 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 100 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
what is a "java.lang.System Property"   ? 20 57
HTTPSessionBindingListernter not configured in deployment descriptor 2 39
session migration servlets 2 26
factorial example 4 35
Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
In this post we will learn how to connect and configure Android Device (Smartphone etc.) with Android Studio. After that we will run a simple Hello World Program.
Viewers will learn about the regular for loop in Java and how to use it. Definition: Break the for loop down into 3 parts: Syntax when using for loops: Example using a for loop:
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …

895 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

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now