Solved

Using a TAB to move around a JTable

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

Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

Join & Write a Comment

For customizing the look of your lightweight component and making it look opaque like it was made of plastic.  This tip assumes your component to be of rectangular shape and completely opaque.   (CODE)
For customizing the look of your lightweight component and making it look lucid like it was made of glass. Or: how to make your component more Apple-ish ;) This tip assumes your component to be of rectangular shape and completely opaque. (COD…
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:
This tutorial explains how to use the VisualVM tool for the Java platform application. This video goes into detail on the Threads, Sampler, and Profiler tabs.

760 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

22 Experts available now in Live!

Get 1:1 Help Now