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

x
?
Solved

Using a TAB to move around a JTable

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

Enroll in October's Free Course of the Month

Do you work with and analyze data? Enroll in October's Course of the Month for 7+ hours of SQL training, allowing you to quickly and efficiently store or retrieve data. It's free for Premium Members, Team Accounts, and Qualified Experts!

Question has a verified solution.

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

INTRODUCTION Working with files is a moderately common task in Java.  For most projects hard coding the file names, using parameters in configuration files, or using command-line arguments is sufficient.   However, when your application has vi…
By the end of 1980s, object oriented programming using languages like C++, Simula69 and ObjectPascal gained momentum. It looked like programmers finally found the perfect language. C++ successfully combined the object oriented principles of Simula w…
This tutorial covers a practical example of lazy loading technique and early loading technique in a Singleton Design Pattern.
This video teaches viewers about errors in exception handling.
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