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?