Skip to Main Content

Java SE (Java Platform, Standard Edition)

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

customize FocusTraversalPolicy need help (JAva 5 &6)

800318May 20 2008 — edited May 20 2008
Hallo all,

I need to customize the focus traversal policy of my JTable which must perform the following things:

1) It shoul set the focus to the next component and leave the JTable if the user clicks on the TAB key on the last cell of the table
2) It should set the focus to the previous component and leave the JTable if the user clicks on Shift+TAB key on the first cell of the table.

So I have read some tutorials about FocusTraversalPolicy and I decided to write my own policy. Here it is
 public class DynTableFocusTraversalPolicy extends FocusTraversalPolicy{

public Component getComponentAfter(Container aContainer, Component aComponent) {
if(aComponent instanceof JTable){
if((((JTable)(aComponent)).getSelectedRow() == ((JTable)(aComponent)).getModel().getRowCount()-1)
&& (((JTable)(aComponent)).getSelectedColumn() == ((JTable)(aComponent)).getModel().getColumnCount()-1)){
{color:#ff0000}// How can I set the return value here?
{color}}
}

return null;
}

public Component getComponentBefore(Container aContainer, Component aComponent) {
return null;
}

public Component getFirstComponent(Container aContainer) {
return (Component)getModel().getValueAt(0,0);
}

public Component getLastComponent(Container aContainer) {
return (Component)getModel().getValueAt(getModel().getRowCount() - 1,getModel().getColumnCount() - 1);
}

public Component getDefaultComponent(Container aContainer) {
return (Component)getModel().getValueAt(0,0);
}
}

So can anyone help me how I can complete the getComponentAfter method? How can I return the next component here?
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Jun 17 2008
Added on May 20 2008
1 comment
203 views