Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / GUI / January 2005

Tip: Looking for answers? Try searching our database.

Focus Traversal problem in Jtable Cell with a Jpanel and multiple components

Thread view: 
Pooja B - 20 Jan 2005 02:11 GMT
I have a custom editor and renderer for a JTable cell to display multiple components e.g textfield, combobox.

When tabbing , the focus moves from cell to cell but I would like to transfer focus to the first component in this particular cell.

I tried to use requestFocus() but the jpanel holding these components is not displayable so it does not work.

Can anybody suggest a solution to this focus problem?
Tom - 21 Jan 2005 12:26 GMT
The problem could be this part of JTable-code:

public Component prepareEditor(TableCellEditor editor, int row, int
column) {
Object value = getValueAt(row, column);
boolean isSelected = isCellSelected(row, column);
Component comp = editor.getTableCellEditorComponent(this, value,
isSelected,
row, column);
if (comp instanceof JComponent) {
JComponent jComp = (JComponent)comp;
if (jComp.getNextFocusableComponent() == null) {
jComp.setNextFocusableComponent(this);            // <-- !!!
}
}
return comp;
}

Means, every time your editor is accessed, nextFocusableComponent is
called on it (nextFocusableComponent is actually deprecated, but you
still find this code in JDK 1.4 / 1.5...), setting the table as next
component. I don't know what the JPanel is doing when it's
setNextFocusableComponent() is used, since a panel normally isn't part
of the focus traversal. You might override prepareEditor(), and change
the  jComp.setNextFocusableComponent(this); to something like (
(MyPanel) jComp).getLastComponent().setNextFocusableComponent(this);.
-Tom
Pooja B - 21 Jan 2005 17:36 GMT
Hi Tom,

Thanks for the reply.
Actually I have a Jpanel table cell.Lets say it has 2 comboboxes and a textfield.
When I tab to this cell, I would like to have focus on the first combobox and then traverse through to second and then textfield .
When the textfield has focus and tab is pressed I would like to transfer the focus to next cell.

Right now tabbing just allows to transfer focus from cell to cell but not within the cell containing jpanel.
Tom - 24 Jan 2005 10:06 GMT
Ok, have a look at the InputMap / ActionMap of the JTable, which is
usually set within the TableUI. InputMap maps an action (e.g. pressing
of the tabKey) to an action-String ("selectNextCell"). The ActionMap
maps this action to an Action (derived from ActionListener). You could
map the VK_TAB to your own action-string, and write your own Action
implenetation that traverses the selection to the next cell, or, in
case you're on your special cell editor, requests the focus for the
first component of your editor.

hth, Tom


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.