sankars98
asked on
JTable Question
Does anyone know how to activate the
CellEditor component when the
user presses Tab key in a JTable ?
TIA,
Sankar S.
make somethink like this
extend JTable
/**
* Override JComponent.processKeyEvent () This allows us to give a special meaning to ENTER and DELETE in the JTable.
* {@link JComponent#registerKeyboar dAction} http://www.javaworld.com/javaworld/javatips/jw-javatip72.html
* @author TogetherSoft LLC
*/
protected void processKeyEvent(KeyEvent e) {
if (e.getID() == KeyEvent.KEY_PRESSED && e.getKeyCode() == KeyEvent.VK_TAB) {
//System.out.println("row= "+row);
int row = getSelectionModel().getAnc horSelecti onIndex()
int column=getSelectedColumn() ;
editCellAt(row, column);
//e.consume(); ?
} else {
super.processKeyEvent(e);
}
}
also look:
http://java.sun.com/docs/books/tutorial/uiswing/components/table.htm
http://manning.spindoczine.com/sbe/files/uts2/Chapter18html/Chapter18.htm
http://users.vnet.net/wwake/swing/faq.html#table
http://www.codeguru.com/java/Swing/JTable/index.shtml
extend JTable
/**
* Override JComponent.processKeyEvent
* {@link JComponent#registerKeyboar
* @author TogetherSoft LLC
*/
protected void processKeyEvent(KeyEvent e) {
if (e.getID() == KeyEvent.KEY_PRESSED && e.getKeyCode() == KeyEvent.VK_TAB) {
//System.out.println("row=
int row = getSelectionModel().getAnc
int column=getSelectedColumn()
editCellAt(row, column);
//e.consume(); ?
} else {
super.processKeyEvent(e);
}
}
also look:
http://java.sun.com/docs/books/tutorial/uiswing/components/table.htm
http://manning.spindoczine.com/sbe/files/uts2/Chapter18html/Chapter18.htm
http://users.vnet.net/wwake/swing/faq.html#table
http://www.codeguru.com/java/Swing/JTable/index.shtml
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
shaveri,
Thank you very much man..
It helped me alot. I included
one more line to enable the
cell editor.
vladi's solution works fine
but the cursor is not blinking
inside the cell.
Here is the code i am using now.
This will help the others.(
have to press two TABS. Have to
do something for that ).
table.registerKeyboardActi
public void actionPerformed (ActionEvent e) {
table.requestFocus();
int ancRow = table.getSelectedRow();
int ancCol = table.getSelectedColumn();
if( (ancRow != -1) && ( ancCol != -1 )){
if ((ancCol + 1) >= table.getColumnCount()) {
ancCol = 0;
ancRow = ((ancRow + 1) >= table.getRowCount()) ? 0 : (ancRow + 1);
}else
ancCol++;
table.setRowSelectionInter
table.setColumnSelectionIn
table.editCellAt( ancRow , ancCol );
DefaultCellEditor editor = (DefaultCellEditor)table.g
if(editor != null ){
editor.getComponent().requ
}
}
}},
KeyStroke.getKeyStroke(Key
JComponent.WHEN_FOCUSED);
Thanks again,
Sankar S.
no points for me :)
ASKER
Vladi ,
Have posted another question
for you. :-).Lock it please..
Thanks,
Sankar S.
Visit this site for examples on JTable
http://www2.gol.com/users/tame/swing/examples/JTableExamples2.html