JTable Question


 Does anyone know how to activate the  
 CellEditor component when the
 user presses Tab key in a JTable ?

 TIA,

 Sankar S.
LVL 1
sankars98Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

vivexpCommented:
Hi,

Visit this site for examples on JTable
http://www2.gol.com/users/tame/swing/examples/JTableExamples2.html
0
vladi21Commented:
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#registerKeyboardAction} 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().getAnchorSelectionIndex()
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
0
shaveriCommented:
visit the site.............
http://www.deja.com/getdoc.xp?AN=371151822
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Cloud Class® Course: C++ 11 Fundamentals

This course will introduce you to C++ 11 and teach you about syntax fundamentals.

sankars98Author Commented:

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.registerKeyboardAction( new AbstractAction() {
                  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.setRowSelectionInterval(ancRow, ancRow);
                              table.setColumnSelectionInterval(ancCol, ancCol);
                              table.editCellAt( ancRow , ancCol );
                              DefaultCellEditor editor = (DefaultCellEditor)table.getCellEditor( ancRow , ancCol );
                              if(editor != null ){
                                    editor.getComponent().requestFocus();
                              }
                        }
                  }},
                  KeyStroke.getKeyStroke(KeyEvent.VK_TAB, 0),
                  JComponent.WHEN_FOCUSED);


 Thanks again,

Sankar S.
0
vladi21Commented:
no points for me :)
0
sankars98Author Commented:

 Vladi ,

   Have posted another question
   for you. :-).Lock it please..

   Thanks,

 Sankar S.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Java

From novice to tech pro — start learning today.