Handling Enter key in JTable

Hi...
What I m trying is to add a blank row to the table,if and only if
the user presses ENTER in the last row(with some data in cell,not blank)
Unfortunately,I m not able to do so . Also I want that the focus
should go to the cell in the next row & previous column.Please help
me with the code...
My code is as follows....
tableView.addKeyListener(ka = new KeyAdapter(){
public void keyPressed(KeyEvent e)
if(e.getKeyCode()==KeyEvent.VK_ENTER)
int selRow = tableView.getSelectedRow();
int rowCount = tableView.getRowCount();
int selCol = tableView.getSelectedColumn();
String val =(String)tableView.getValueAt(selRow,selCol);
System.out.println(rowCount-1 + " "+ selRow + " " + tableView.getSelectedColumn());
if((!val.equals("")) && selRow==rowCount-1)
System.out.println(rowCount-1 + " "+ tableView.getSelectedRow()+ " " + tableView.getSelectedColumn());
blank1 = new String[columns];
for(int p=0;p<columns;p++)
blank1[p]="";
datarows.addElement(blank1);
//dataModel.fireTableDataChanged();
dataModel.fireTableChanged(null);
I do get the desired result ,but the second time I press Enter
in the same cell...
Please help me to get out of this annoying problem.....
Thanx in advance...
Piyush

Hi...
First of all thanks both of u....
But my problem is not completely solved...
I have four columns in my table.What I want is when the user presses
ENTER in the last row and 2nd or 4th column new row should be appended
and the input focus should be at (selectedRow+1,selectedCol-1),that is,
diagonally...
But when I press ENTER fot the first time,nothing happens...
Again when I come back to the same cell(second time) and press ENTER,
I get the desired results...
I think the cellEditor's stopCellEditing() method should be called,
but it throws exception....
Here's my _enterKeyHit() method....
private void _enterKeyHit()
// Enter hit on last row... do stuff
int selRow = tableView.getSelectedRow();
int rowCount = tableView.getRowCount();
int selCol = tableView.getSelectedColumn();
String val =(String)tableView.getValueAt(selRow,selCol);
//-- Throws Exception....
boolean res=tableView.getCellEditor().stopCellEditing();
if((!val.equals("")) && selRow==rowCount-1 && (selCol==1 || selCol==3))
System.out.println(rowCount-1 + " "+ tableView.getSelectedRow()+ " " + tableView.getSelectedColumn());
blank1 = new String[columns];
for(int p=0;p<columns;p++)
blank1[p]="";
datarows.addElement(blank1);
dataModel.fireTableChanged(null);
tableView.editCellAt(selRow+1,selCol-1);
if(!val.equals("") && selRow!=rowCount-1)
if(selCol==1 || selCol==3)
tableView.editCellAt(selRow+1,selCol-1);
else
tableView.editCellAt(selRow,selCol+1);
if((!val.equals("")) && selRow==rowCount-1 && (selCol==0 || selCol==2))
tableView.editCellAt(selRow,selCol+1);
}

Similar Messages

  • Handling Enter key event in JTable

    Hi...
    This is particularly for the user "VIRAVAN"...
    I have followed your method ,and got results too.. but the
    processKeyBinding(.. method is called 4 times,same problem addressed by you before, but I didn't understood it...
    Please help me...
    Here is my code...
    protected boolean processKeyBinding(KeyStroke ks, KeyEvent e,int condition, boolean pressed)
    System.out.println("Wait");
    if (ks == KeyStroke.getKeyStroke(KeyEvent.VK_ENTER,0))
    int selRow = getSelectedRow();
    int rowCount = getRowCount();
    int selCol = getSelectedColumn();
    String val =(String)getValueAt(selRow,selCol);
    boolean b= getCellEditor(selRow,selCol).stopCellEditing();
    System.out.println(b);
    System.out.println(rowCount-1 + " "+ selRow + " " + getSelectedColumn());
    if((!val.equals("")) && selRow==rowCount-1)
    System.out.println(rowCount-1 + " "+ getSelectedRow()+ " " + getSelectedColumn());
    blank1 = new String[columns];
    for(int p=0;p<columns;p++)
    blank1[p]="";
    Diary.this.datarows.addElement(blank1);
    // dataModel.fireTableStructureChanged();
    //dataModel.fireTableDataChanged();
    Diary.this.dataModel.fireTableChanged(null);
    else if(ks ==KeyStroke.getKeyStroke(KeyEvent.VK_1,0))
    System.out.println("One One One One ");
    return super.processKeyBinding(ks,e,condition,pressed);

    It's been a while since I looked at the code, but essentially there are three key event types:
    1) key pressed,
    2) key typed,
    3) key released.
    So I would expect the processKeyBind to see all three of them. However, ks==KeyStroke.getKeyStroke(KeyEvent.VK_ENTER,0) is true only when a key typed event is detected (the other types can be ignored by passing it up the food chain where they will eventually be consumed). Now...., if I understand you correctly, you want to terminate edit on the present of Enter key, right? Here is how I'd suggest you do:
       protected boolean processKeyBinding(KeyStroke ks, KeyEvent e, int condition, boolean pressed) {
          if (isEditing()) {
             Component editorComponent=getEditorComponent();
             editorComponent.stopCellEditing();
             return true;
          return super.processKeyBinding(ks,e,condition,pressed);
       }Ok.... now, it appears that you want to do something else also... i.e., add a new row to the table if the editing row is the last row and the editing column is the last column of the last row. You can't do that in the same thread (i.e., you must wait until the update in the current thread is completed). So, what you must do is use the SwingUtilities.InvokeLater, like this:
       protected boolean processKeyBinding(KeyStroke ks, KeyEvent e, int condition, boolean pressed) {
          if (isEditing()) {
             Component editorComponent=getEditorComponent();
             editorComponent.stopCellEditing();
             if (getEditingRow()+1==getRowCount() && getEditingColumn()+1==getColumnCount()) {
                SwingUtilities.invokeLater(new Runnable() {
                   public void run() {
    // put the code for adding new row here
             return true;
          return super.processKeyBinding(ks,e,condition,pressed);
       }OK?
    ;o)
    V.V.
    PS: posted code is untest but should work!

  • Handling 'enter key' event in alv using classes

    Hello all,
        i have a scenario where i have a grid from which i have to select a row and press 'enter' key, then the row would be added to grid on top of it. we have developed this grids using control and classes.
        please any one tell me how would i get the enter key code.
    Thanks,
    krishnam raju N

    HI Raju
    just go through these
    check the sample program.
    <b>BALV_POPUP_TO_SELECT
    ENTER is nothing but selecting the record.
    </b>
    Re: ALV  'ENTER' key
    and go through this code
    constants :
    C_PF_STATUS TYPE SLIS_FORMNAME VALUE 'F_SET_PF_STATUS'.
    CALL FUNCTION 'REUSE_ALV_LIST_DISPLAY'
    EXPORTING
    I_CALLBACK_PROGRAM = V_REPID
    I_CALLBACK_PF_STATUS_SET = C_PF_STATUS
    I_CALLBACK_USER_COMMAND = P_USER_COMMAND IS_LAYOUT = WA_LAYOUT
    IT_FIELDCAT = IT_FIELDCAT[]
    IT_EXCLUDING = IT_EXTAB[]
    IT_SORT = IT_SORT[]
    TABLES
    T_OUTTAB = P_ZBCAR50
    EXCEPTIONS
    PROGRAM_ERROR = 1
    OTHERS = 2.
    IF SY-SUBRC <> 0.
    MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
    WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
    ENDIF.
    2.
    *& Form F_SET_PF_STATUS
    Set PF_STATUS STANDARD modifying the standard toolbar
    by excluding some buttons
    -->P_IT_EXTAB -- TABLE OF EXCLUDING FUNCTIONS
    FORM F_SET_PF_STATUS USING RT_EXTAB TYPE SLIS_T_EXTAB.
    CLEAR : WA_EXTAB,
    IT_EXTAB.
    *--Set the Modified PF status for the ALV.
    SET PF-STATUS 'STATUS_01' EXCLUDING RT_EXTAB.
    ENDFORM. " SET_PF_STATUS
    3.
    *& Form f_user_command
    Handle user action on ALV toolbar
    FORM F_USER_COMMAND USING R_UCOMM LIKE SY-UCOMM
    RS_SELFIELD TYPE SLIS_SELFIELD.
    DATA : L_ANSWER TYPE C.
    RS_SELFIELD-REFRESH = C_X.
    IF R_UCOMM = 'ENTR'.
    Do your processing here.
    ENDIF
    and go through these links
    <b>how to identify pressing ENTER on ALV
    How to capture the event in ALV grid display?
    Re: ALV-Grid: No reaction to Enter-Button
    </b>
    IF IT HELPS REWARD WITH POINTS
    Regards Rk
    Message was edited by:
            Rk Pasupuleti

  • Handling Enter Key in Editable ALV Grid using REUSE_ALV_GRID_DISPLAY

    Hello All,
    I have seen a number of threads on captioned issue and everyone of them say to create FCODE for Enter in the Screen's PF Status and then handle the event.
    But the catch is when you hit Enter key in ALV Grid, it will not trigger any FCODE at all because the FCODE Enter you have created is for the screen and not for the GRID. Can anyone please let me know if SAP has given any standard utility in REUSE_ALV_GRID_DISPLAY FM for handling the Enter key event.
    Thanks and regards,
    Mahesh

    Hi,
    Set the PF-status for OK key and use the FCODE or u can usethe dynamic ok_code generated .
    Also try 'ENTE' .
    Hope thishelps.

  • Enter Key in JTable

    Hi All,
    I have used the JTable in my application . Here my problem is when I press the Tab in the
    table cell (TextCellEditor/Render) the message is popping up . But the same message need to be
    populated when I press the Enter key .Can any one suggest me what might be the problem ?
    My Table is generically written for entire application.
    Thanks in Advance

    [http://catb.org/~esr/faqs/smart-questions.html]
    To get better help sooner, post a SSCCE that clearly demonstrates your problem.
    Use code tags to post codes -- [code]CODE[/code] will display asCODEOr click the CODE button and paste your code between the {code} tags that appear.
    db

  • Returns wrong row number with ENTER key in JTable...

    I am having a problem to get exact row number ofJTable when ENTER key is pressed.
    table.getSelectedRow() always retuns one more value when ENTER key is pressed(fired). like
    if i have 5 rows in a table and when my focus is on 1st row and then i press enter key focus moves to next row and it returns 1 instead of 0 for the 1st row.
    I have written a code bellow, please check it out and tell me why it happens. Please click on Add Row button for creating rows in table.
    import javax.swing.*;
       import javax.swing.table.*;
       import java.awt.*;
       import java.awt.event.*;
       import java.util.Vector;
       class TableTest extends JFrame {
         MyTableModel myModel;
         JTable table;
         JButton button;
         JButton buttonQuery;
         int count = 0;
         public TableTest() {
           myModel = new MyTableModel();
           table = new JTable(myModel);
           table.setPreferredScrollableViewportSize(new Dimension(500, 200));
           JScrollPane scrollPane = new JScrollPane(table);
          table.addKeyListener(new KeyAdapter(){
              public void keyTyped(KeyEvent ke)
                if(ke.getKeyChar() == ke.VK_ENTER){
                  System.out.println(table.getSelectedRow());
           getContentPane().add(scrollPane, BorderLayout.CENTER);
           getContentPane().add(button = new JButton("Add Row"),
           BorderLayout.SOUTH);
           getContentPane().add(buttonQuery = new JButton("Query"), BorderLayout.NORTH);
           button.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
          Object [] aRow = new Object [8];
         String aRow1;
         for (int i=0; i<5; i++) {}
         myModel.addRow(aRow);
       buttonQuery.addActionListener(new ActionListener() {
         public void actionPerformed(ActionEvent e) {
           System.out.println(myModel.getRowCount());
           System.out.println(myModel.getValueAt(1, 3));
       addWindowListener(new WindowAdapter() {
         public void windowClosing(WindowEvent e) {
           System.exit(0);
       class MyTableModel extends AbstractTableModel {
       protected final String[] headers =
       { "No", "Vehicle No", "Date of Loss", "Image Type", "Image Description", "Claim Type", "Scan Date", "User Id" };
       Vector data;
       MyTableModel() {
        data = new Vector();
       public int getColumnCount() {
         return headers.length;
       public int getRowCount() {
        return data.size();
       public Object getValueAt(int row, int col) {
       if (row < data.size() && col < 8) {
         Object [] aRow = (Object []) data.elementAt(row);
       return aRow[col];
       } else {
         return null;
       public void addRow(Object [] aRow) {
         data.addElement(aRow);
        fireTableRowsInserted(data.size()-1, data.size()-1);
       public static void main(String[] args) {
       TableTest frame = new TableTest();
       frame.pack();
       frame.setVisible(true);
       }Regards..
    jaya

    Dear Jaya,
    I have a look at your code. And modified a bit as well to really check the getSelectedRow(). Here's the modified code: I think when key event fired, the table row is changed and then is displays the get selected row. You can check this, if you are on the last row, and you press enter, it displays 0, it means first it changes the row and then displays the selected row which is obviously rowNumber+1.
    Hope it helps.
    import javax.swing.*;
    import javax.swing.table.*;
    import java.awt.*;
    import java.awt.event.*;
    import java.util.Vector;
    class TableTest
        extends JFrame {
      MyTableModel myModel;
      JTable table;
      JButton button;
      JButton buttonQuery;
      JButton buttonSelectedRow;
      int count = 0;
      public TableTest() {
        myModel = new MyTableModel();
        table = new JTable(myModel);
        table.setPreferredScrollableViewportSize
            (new Dimension(500, 200));
        JScrollPane scrollPane = new JScrollPane(table);
        table.addKeyListener(new KeyAdapter() {
          public void keyTyped(KeyEvent ke) {
            if (ke.getKeyChar() == ke.VK_ENTER) {
              System.out.println(table.getSelectedRow());
        getContentPane().add(scrollPane, BorderLayout.CENTER);
        getContentPane().add(button = new JButton("Add Row"), BorderLayout.SOUTH);
        getContentPane().add(buttonQuery = new JButton("Query"), BorderLayout.NORTH);
        getContentPane().add(buttonSelectedRow = new JButton("Get Selected Row Number"), BorderLayout.NORTH);
        button.addActionListener(new ActionListener() {
          public void actionPerformed(ActionEvent e) {
            Object[] aRow = new Object[8];
            String
                aRow1;
            for (int i = 0; i < 5; i++) {}
            myModel.addRow(aRow);
        buttonSelectedRow.addActionListener(new ActionListener() {
          public void actionPerformed(ActionEvent e) {
            System.out.println("Selected Row is: " + table.getSelectedRow());
        buttonQuery.addActionListener(new ActionListener() {
          public void actionPerformed(ActionEvent e) {
            System.out.println(myModel.getRowCount());
            System.out.println(myModel.getValueAt(1, 3));
        addWindowListener(new WindowAdapter() {
          public void windowClosing(WindowEvent e) {
            System.exit(0);
      class MyTableModel
          extends AbstractTableModel {
        protected final String[] headers = {
            "No", "Vehicle No", "Date of Loss", "Image Type", "Image Description",
            "Claim Type", "Scan Date", "User Id"};
        Vector data;
        MyTableModel() {
          data = new Vector();
        public int getColumnCount() {
          return headers.length;
        public int getRowCount() {
          return data.size();
        public Object getValueAt(int row, int col) {
          if (row < data.size() && col < 8) {
            Object[] aRow = (Object[]) data.elementAt(row);
            return aRow[col];
          else {
            return null;
        public void addRow(Object[] aRow) {
          data.addElement(aRow);
          fireTableRowsInserted(data.size() - 1, data.size() - 1);
      public static void main(String[] args) {
        TableTest frame = new TableTest();
        frame.pack();
        frame.setVisible(true);

  • Handling "enter" key while a user clicks a button being displayed in datagrid

    Hi,
    I have a datagrid of which one non editable column has an itemrenderer render a button while a row is hovered or selected. I am usinhg default tab handling of datagrid. I want to handle the button click event when a user presses enter key while the focus is on this tabbed column.
    Can anyone help me how to ahcieve this?

    This how my datagrid looks ..main file
    <?xml version="1.0" encoding="utf-8"?>
    <s:Application xmlns:fx="http://ns.adobe.com/mxml/2009"
                   xmlns:s="library://ns.adobe.com/flex/spark"
                   xmlns:mx="library://ns.adobe.com/flex/mx" minWidth="955" minHeight="600">
        <fx:Script>
            <![CDATA[
                import mx.controls.Alert;
                public function myKeyDownEvent(event:Event):void{
                    mx.controls.Alert.show("Selected " + myGrid.columns[0].popupIndex);
            ]]>
        </fx:Script>
        <fx:Declarations>
            <fx:XMLList id="transactions">
                <transaction>
                    <type>Unassigned</type>
                    <date>11-21-2009</date>
                    <payee>CREDITCARD debit 328</payee>
                    <payment>10</payment>
                    <deposit>0</deposit>
                    <account>My Visa</account>
                </transaction>
                <transaction>
                    <type>Match</type>
                    <date>11-23-2009</date>
                    <payee>SAVINGS debit 323</payee>
                    <payment>10</payment>
                    <deposit>0</deposit>
                    <account>My Savings</account>
                </transaction>
                <transaction>
                    <type>Unassigned</type>
                    <date>11-24-2009</date>
                    <payee>CREDITCARD debit 328</payee>
                    <payment>0</payment>
                    <deposit>20</deposit>
                    <account>My Visa</account>
                </transaction>
                <transaction>
                    <type>Unassigned</type>
                    <date>11-23-2009</date>
                    <payee>SAVINGS debit 327</payee>
                    <payment>0</payment>
                    <deposit>10</deposit>
                    <account>My Savings</account>
                </transaction>
                <transaction>
                    <type>Unassigned</type>
                    <date>11-21-2009</date>
                    <payee>CREDITCARD debit 328</payee>
                    <payment>10</payment>
                    <deposit>0</deposit>
                    <account>My Visa</account>
                </transaction>
                <transaction>
                    <type>Unassigned</type>
                    <date>11-21-2009</date>
                    <payee>CREDITCARD debit 328</payee>
                    <payment>10</payment>
                    <deposit>0</deposit>
                    <account>My Visa</account>
                </transaction>
                <transaction>
                    <type>Unassigned</type>
                    <date>11-21-2009</date>
                    <payee>CREDITCARD debit 328</payee>
                    <payment>10</payment>
                    <deposit>0</deposit>
                    <account>My Visa</account>               
                </transaction>
                <transaction>
                    <type>Unassigned</type>
                    <date>11-21-2009</date>
                    <payee>CREDITCARD debit 328</payee>
                    <payment>10</payment>
                    <deposit>0</deposit>
                    <account>My Visa</account>               
                </transaction>
                <transaction>
                    <type>Unassigned</type>
                    <date>11-21-2009</date>
                    <payee>CREDITCARD debit 328</payee>
                    <payment>10</payment>
                    <deposit>0</deposit>
                    <account>My Visa</account>               
                </transaction>
                <transaction>
                    <type>Unassigned</type>
                    <date>11-21-2009</date>
                    <payee>CREDITCARD debit 328</payee>
                    <payment>10</payment>
                    <deposit>0</deposit>
                    <account>My Visa</account>               
                </transaction>
                <transaction>
                    <type>Unassigned</type>
                    <date>11-21-2009</date>
                    <payee>CREDITCARD debit 328</payee>
                    <payment>10</payment>
                    <deposit>0</deposit>
                    <account>My Visa</account>               
                </transaction>
                <transaction>
                    <type>Unassigned</type>
                    <date>11-21-2009</date>
                    <payee>CREDITCARD debit 328</payee>
                    <payment>10</payment>
                    <deposit>0</deposit>
                    <account>My Visa</account>               
                </transaction>
                <transaction>
                    <type>Unassigned</type>
                    <date>11-21-2009</date>
                    <payee>CREDITCARD debit 328</payee>
                    <payment>10</payment>
                    <deposit>0</deposit>
                    <account>My Visa</account>               
                </transaction>
                <transaction>
                    <type>Unassigned</type>
                    <date>11-21-2009</date>
                    <payee>CREDITCARD debit 328</payee>
                    <payment>10</payment>
                    <deposit>0</deposit>
                    <account>My Visa</account>               
                </transaction>
                <transaction>
                    <type>Unassigned</type>
                    <date>11-21-2009</date>
                    <payee>CREDITCARD debit 328</payee>
                    <payment>10</payment>
                    <deposit>0</deposit>
                    <account>My Visa</account>               
                </transaction>
                <transaction>
                    <type>Unassigned</type>
                    <date>11-21-2009</date>
                    <payee>CREDITCARD debit 328</payee>
                    <payment>10</payment>
                    <deposit>0</deposit>
                    <account>My Visa</account>               
                </transaction>
                <transaction>
                    <type>Unassigned</type>
                    <date>11-21-2009</date>
                    <payee>CREDITCARD debit 328</payee>
                    <payment>10</payment>
                    <deposit>0</deposit>
                    <account>My Visa</account>               
                </transaction>
                <transaction>
                    <type>Unassigned</type>
                    <date>11-21-2010</date>
                    <payee>CREDITCARD debit 328</payee>
                    <payment>10</payment>
                    <deposit>0</deposit>
                    <account>My Visa</account>               
                </transaction>
                <transaction>
                    <type>Unassigned</type>
                    <date>11-21-2010</date>
                    <payee>CREDITCARD debit 328</payee>
                    <payment>10</payment>
                    <deposit>0</deposit>
                    <account>My Visa</account>
                </transaction>
                <transaction>
                    <type>Match</type>
                    <date>11-23-2010</date>
                    <payee>SAVINGS debit 323</payee>
                    <payment>10</payment>
                    <deposit>0</deposit>
                    <account>My Savings</account>
                </transaction>
                <transaction>
                    <type>Unassigned</type>
                    <date>11-24-2010</date>
                    <payee>CREDITCARD debit 328</payee>
                    <payment>0</payment>
                    <deposit>20</deposit>
                    <account>My Visa</account>
                </transaction>
                <transaction>
                    <type>Unassigned</type>
                    <date>11-23-2010</date>
                    <payee>SAVINGS debit 327</payee>
                    <payment>0</payment>
                    <deposit>10</deposit>
                    <account>My Savings</account>
                </transaction>
                <transaction>
                    <type>Unassigned</type>
                    <date>11-21-2010</date>
                    <payee>CREDITCARD debit 328</payee>
                    <payment>10</payment>
                    <deposit>0</deposit>
                    <account>My Visa</account>
                </transaction>
                <transaction>
                    <type>Unassigned</type>
                    <date>11-21-2010</date>
                    <payee>CREDITCARD debit 328</payee>
                    <payment>10</payment>
                    <deposit>0</deposit>
                    <account>My Visa</account>
                </transaction>
                <transaction>
                    <type>Unassigned</type>
                    <date>11-21-2010</date>
                    <payee>CREDITCARD debit 328</payee>
                    <payment>10</payment>
                    <deposit>0</deposit>
                    <account>My Visa</account>               
                </transaction>
                <transaction>
                    <type>Unassigned</type>
                    <date>11-21-2010</date>
                    <payee>CREDITCARD debit 328</payee>
                    <payment>10</payment>
                    <deposit>0</deposit>
                    <account>My Visa</account>               
                </transaction>
                <transaction>
                    <type>Unassigned</type>
                    <date>11-21-2010</date>
                    <payee>CREDITCARD debit 328</payee>
                    <payment>10</payment>
                    <deposit>0</deposit>
                    <account>My Visa</account>               
                </transaction>
                <transaction>
                    <type>Unassigned</type>
                    <date>11-21-2010</date>
                    <payee>CREDITCARD debit 328</payee>
                    <payment>10</payment>
                    <deposit>0</deposit>
                    <account>My Visa</account>               
                </transaction>
                <transaction>
                    <type>Unassigned</type>
                    <date>11-21-2010</date>
                    <payee>CREDITCARD debit 328</payee>
                    <payment>10</payment>
                    <deposit>0</deposit>
                    <account>My Visa</account>               
                </transaction>
                <transaction>
                    <type>Unassigned</type>
                    <date>11-21-2010</date>
                    <payee>CREDITCARD debit 328</payee>
                    <payment>10</payment>
                    <deposit>0</deposit>
                    <account>My Visa</account>               
                </transaction>
                <transaction>
                    <type>Unassigned</type>
                    <date>11-21-2010</date>
                    <payee>CREDITCARD debit 328</payee>
                    <payment>10</payment>
                    <deposit>0</deposit>
                    <account>My Visa</account>               
                </transaction>
                <transaction>
                    <type>Unassigned</type>
                    <date>11-21-2009</date>
                    <payee>CREDITCARD debit 328</payee>
                    <payment>10</payment>
                    <deposit>0</deposit>
                    <account>My Visa</account>               
                </transaction>
                <transaction>
                    <type>Unassigned</type>
                    <date>11-21-2009</date>
                    <payee>CREDITCARD debit 328</payee>
                    <payment>10</payment>
                    <deposit>0</deposit>
                    <account>My Visa</account>               
                </transaction>
                <transaction>
                    <type>Unassigned</type>
                    <date>11-21-2009</date>
                    <payee>CREDITCARD debit 328</payee>
                    <payment>10</payment>
                    <deposit>0</deposit>
                    <account>My Visa</account>               
                </transaction>
                <transaction>
                    <type>Unassigned</type>
                    <date>11-21-2009</date>
                    <payee>CREDITCARD debit 328</payee>
                    <payment>10</payment>
                    <deposit>0</deposit>
                    <account>My Visa</account>               
                </transaction>
                <transaction>
                    <type>Unassigned</type>
                    <date>11-21-2009</date>
                    <payee>CREDITCARD debit 328</payee>
                    <payment>10</payment>
                    <deposit>0</deposit>
                    <account>My Visa</account>               
                </transaction>
            </fx:XMLList>
        </fx:Declarations>
        <mx:DataGrid id="myGrid" width="100%" height="100%" dataProvider="{transactions}" editable="true" allowMultipleSelection="true" rollOverColor="0x9BDFFA"
                     selectionColor="0x004B8D" textSelectedColor="white">
            <mx:columns>
                <mx:DataGridColumn headerText="Type" dataField="type" itemRenderer="TypeItemRenderer" editable="false"/>
                <mx:DataGridColumn headerText="Date" dataField="date" />
                <mx:DataGridColumn headerText="Payee" dataField="payee" />
                <mx:DataGridColumn headerText="Envelope" dataField="envelope" editable="false" />
                <mx:DataGridColumn headerText="Payment" dataField="payment" />
                <mx:DataGridColumn headerText="Deposit" dataField="deposit" />
                <mx:DataGridColumn headerText="Account" dataField="account" editable="false"/>
            </mx:columns>
        </mx:DataGrid>
    </s:Application>

  • How to handle 'ENTER' Key on ALV Editable Grid on sub screen (Tabstrips)

    Hello Experts ,
    I have 2 questions with ALV Editable grid;
    please help me if you have answers.
    I created ALV grid on one of sub screens on a Tab Strip,
    As soon as user types one of the columns of the ALV grid and press u2018ENTERu2019 key, it has to return corresponding details for that line.
    I tried to implement this logic in ALV grid event u2018handle_data_changedu2019, but ALV internal table is not getting populated with new entry entered in the grid. but u2018double_clicku2019 event working my purpose, but user might need enter key.
    and I thought I would do implement that logic in PAI event of the sub screen, u2018ENTERu2019 key not getting trigger on PAI event of the screen until cursor is on grid.
    Another question 2:  How do I control and not to be deleted a line on the grid (based on validation), where do I validate and by pass the delete function for a particular line, or suggest me to gray out only one line on the grid .
    I would like to have delete function to work as it is ,except for some validations..
    Can I implement using PAI event of the sub screen or any by ALV event.
    Please suggest me..
    Edited by: Ravindranath Arusam on May 13, 2010 2:42 PM

    In DATA_CHANGED event, you will get the modified row into the attribute MP_MOD_ROWS of the impoerting object ER_DATA_CHANGED. Since this MP_MOD_ROWS is the Object reference to Data, you need to have the field symbol to get the value.
      FIELD-SYMBOLS:  <lft_mod_output>  TYPE t_t_output.
      ASSIGN  er_data_changed->mp_mod_rows->* TO <lft_mod_output>.
    You can get the Value of the Cell by using the method GET_CELL_VALUE of the same ER_DATA_CHANGED object and use the method MODIFY_CELL To update the value back to ALV.
    To Restrict the row deletion:
    When the row is deleted it is being added to Attribute mt_deleted_rows of the object ER_DATA_CHANGED. You can put the data back to the table in the DATA_CHANGE_FINISHED event. Visit this post http://help-abap.blogspot.com/2008/10/alv-disable-delete-key-on-keyboard-in.html for more information.
    Regards,
    Naimesh Patel

  • OAF: Handling "ENTER" key

    Hi,
    If I have a requirement in OAF that:
    I need to move the cursor to next item when the user hits the "ENTER" key on an text item, is it possible in OAF?
    Please let me know.
    Thanks,
    Ashu.

    How posting the same issue in two threads going to help ? it is not possible.
    Tapash

  • Editable ALV - handling Enter key  when pressing enter on keyboard

    Hi folks.
    Now I have searched - and found a lot of threads - in this forum about my little problem.
    I'm using the <b>Function Module: REUSE_ALV_GRID_DISPLAY - NOT THE OO-version</b>!!!!!
    I have a editable list as result of finding some data. My problem is.
    When I change the value in one of the cells, and press the Enter key (not a click with the mouse on the Green button with the checkmark!) nothing happens!
    I have
        i_callback_pf_status_set  = 'SET_PF_STATUS'
        i_callback_user_command   = 'USER_COMMAND'
    And when I put a breakpoint in the USER_COMMAND form nothing happens - <b>ONLY IF I CLIKS WITH MY MOUSE ON THE Green button with the checkmark</b>!!
    Hope U have some idea!
    Best regards
    Carsten :o)

    Hi,
    Following the sample program for EDITABLE BLOCK ALV report.
    REPORT  YMS_EDITBLOCKALV.
    TABLES : rmmg1,MCHB, mkpf.
    DATA: BEGIN OF t_mseg OCCURS 0,
            zeile LIKE mseg-zeile,
            menge LIKE mseg-menge,
            meins LIKE mseg-meins,
            matnr LIKE mseg-matnr,
            werks LIKE mseg-werks,
            charg LIKE mseg-charg,
            bwart LIKE mseg-bwart,
    END OF t_mseg.
    DATA:BEGIN OF t_mchb OCCURS 0.
    INCLUDE STRUCTURE mchb.
    data flag type c.
    matnr LIKE mchb-matnr,
    charg LIKE mchb-charg,
    werks LIKE mchb-werks,
    clabs LIKE mchb-clabs,
    DATA END OF t_mchb.
    TYPE-POOLS slis.
    data: progname like sy-repid,
    fieldcattab TYPE slis_t_fieldcat_alv WITH HEADER LINE.
    data tabindex type i.
    data wa_matnr LIKE mchb-matnr.
    progname = sy-repid.
    SELECTION-SCREEN BEGIN OF BLOCK b_b1 WITH FRAME TITLE text-001.
    SELECT-OPTIONS s_docno FOR mkpf-mblnr OBLIGATORY.
    PARAMETERS p_docyr LIKE mkpf-mjahr OBLIGATORY.
    SELECTION-SCREEN END OF BLOCK b_b1.
    START-OF-SELECTION.
    SELECT zeile
    menge
    meins
    matnr
    werks
    charg
    bwart
    FROM mseg
    INTO TABLE t_mseg
    WHERE mblnr IN s_docno AND mjahr = p_docyr.
    CLEAR fieldcattab.
    fieldcattab-col_pos = 1.
    fieldcattab-fieldname = 'ZEILE'.
    fieldcattab-tabname = 'T_MSEG'.
    fieldcattab-fix_column = 'X'.
    fieldcattab-seltext_l = 'Item'.
    APPEND fieldcattab.
    CLEAR fieldcattab.
    fieldcattab-col_pos = 2.
    fieldcattab-fieldname = 'MENGE'.
    fieldcattab-tabname = 'T_MSEG'.
    fieldcattab-seltext_l = 'Quantity'.
    APPEND fieldcattab.
    CLEAR fieldcattab.
    fieldcattab-col_pos = 3.
    fieldcattab-fieldname = 'MEINS'.
    fieldcattab-tabname = 'T_MSEG'.
    fieldcattab-seltext_l = 'Unit'.
    APPEND fieldcattab.
    CLEAR fieldcattab.
    fieldcattab-col_pos = 4.
    fieldcattab-fieldname = 'MATNR'.
    fieldcattab-tabname = 'T_MSEG'.
    fieldcattab-seltext_l = 'Material'.
    APPEND fieldcattab.
    CLEAR fieldcattab.
    fieldcattab-col_pos = 5.
    fieldcattab-fieldname = 'WERKS'.
    fieldcattab-tabname = 'T_MSEG'.
    fieldcattab-seltext_l = 'Plant'.
    APPEND fieldcattab.
    CLEAR fieldcattab.
    fieldcattab-col_pos = 6.
    fieldcattab-fieldname = 'CHARG'.
    fieldcattab-tabname = 'T_MSEG'.
    fieldcattab-seltext_l = 'Batch No'.
    APPEND fieldcattab.
    CLEAR fieldcattab.
    fieldcattab-col_pos = 7.
    fieldcattab-fieldname = 'BWART'.
    fieldcattab-tabname = 'T_MSEG'.
    fieldcattab-seltext_l = 'Inventory'.
    fieldcattab-hotspot = 'X'.
    APPEND fieldcattab.
    end-of-selection.
    CALL FUNCTION 'REUSE_ALV_LIST_DISPLAY'
    EXPORTING
    I_INTERFACE_CHECK = ' '
    I_BYPASSING_BUFFER =
    I_BUFFER_ACTIVE = ' '
    I_CALLBACK_PROGRAM = PROGNAME
    I_CALLBACK_PF_STATUS_SET = ' '
    I_CALLBACK_USER_COMMAND = 'USERCOMMAND1'
    I_CALLBACK_TOP_OF_PAGE = ' '
    I_CALLBACK_HTML_TOP_OF_PAGE = ' '
    I_CALLBACK_HTML_END_OF_LIST = ' '
    I_STRUCTURE_NAME =
    I_BACKGROUND_ID = ' '
    I_GRID_TITLE =
    I_GRID_SETTINGS =
    IS_LAYOUT =
    IT_FIELDCAT = fieldcattab[]
    IT_EXCLUDING =
    IT_SPECIAL_GROUPS =
    IT_SORT =
    IT_FILTER =
    IS_SEL_HIDE =
    I_DEFAULT = 'X'
    I_SAVE = ' '
    IS_VARIANT =
    IT_EVENTS =
    IT_EVENT_EXIT =
    IS_PRINT =
    IS_REPREP_ID =
    I_SCREEN_START_COLUMN = 0
    I_SCREEN_START_LINE = 0
    I_SCREEN_END_COLUMN = 0
    I_SCREEN_END_LINE = 0
    IT_ALV_GRAPHICS =
    IT_ADD_FIELDCAT = fieldcattab
    IT_HYPERLINK =
    IMPORTING
    E_EXIT_CAUSED_BY_CALLER =
    ES_EXIT_CAUSED_BY_USER =
    TABLES
    t_outtab = t_mseg
    EXCEPTIONS
    PROGRAM_ERROR = 1
    OTHERS = 2
    IF sy-subrc <> 0.
    MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
    WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
    ENDIF.
    FORM usercommand1 USING r_ucomm LIKE sy-ucomm rs_selfield TYPE
    slis_selfield.
    CASE r_ucomm.
    WHEN '&IC1'.
    tabindex = rs_selfield-tabindex.
    read table t_mseg INDEX tabindex.
    select * from mchb into table t_mchb where matnr = t_mseg-matnr.
    clear fieldcattab.
    CLEAR fieldcattab[].
    fieldcattab-col_pos = 1.
    fieldcattab-fieldname = 'FLAG'.
    fieldcattab-tabname = 'T_MCHB'.
    fieldcattab-fix_column = 'X'.
    fieldcattab-seltext_l = 'Check Box'.
    fieldcattab-input = 'X'.
    fieldcattab-edit = 'X'.
    fieldcattab-checkbox = 'X'.
    APPEND fieldcattab.
    clear fieldcattab.
    fieldcattab-col_pos = 2.
    fieldcattab-fieldname = 'MATNR'.
    fieldcattab-tabname = 'T_MCHB'.
    fieldcattab-fix_column = 'X'.
    fieldcattab-seltext_l = 'Material'.
    fieldcattab-emphasize = 'C1'.
    fieldcattab-input = 'X'.
    fieldcattab-edit = 'X'.
    fieldcattab-checkbox = 'X'.
    APPEND fieldcattab.
    clear fieldcattab.
    fieldcattab-col_pos = 3.
    fieldcattab-fieldname = 'CHARG'.
    fieldcattab-tabname = 'T_MCHB'.
    fieldcattab-seltext_l = 'Batch No'.
    fieldcattab-emphasize = 'C2'.
    fieldcattab-input = 'X'.
    fieldcattab-edit = 'X'.
    APPEND fieldcattab.
    clear fieldcattab.
    fieldcattab-col_pos = 4.
    fieldcattab-fieldname = 'WERKS'.
    fieldcattab-tabname = 'T_MCHB'.
    fieldcattab-seltext_l = 'Plant'.
    fieldcattab-emphasize = 'C30'.
    fieldcattab-input = 'X'.
    fieldcattab-edit = 'X'.
    APPEND fieldcattab.
    clear fieldcattab.
    fieldcattab-col_pos = 5.
    fieldcattab-fieldname = 'CLABS'.
    fieldcattab-tabname = 'T_MCHB'.
    fieldcattab-seltext_l = 'Stock'.
    fieldcattab-emphasize = 'C601'.
    fieldcattab-input = 'X'.
    fieldcattab-edit = 'X'.
    APPEND fieldcattab.
    CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
    EXPORTING
    I_INTERFACE_CHECK = ' '
    I_BYPASSING_BUFFER =
    I_BUFFER_ACTIVE = ' '
    I_CALLBACK_PROGRAM = PROGNAME
    I_CALLBACK_PF_STATUS_SET = ' '
    I_CALLBACK_USER_COMMAND = 'USERCOMMAND2'
    I_CALLBACK_TOP_OF_PAGE = ' '
    I_CALLBACK_HTML_TOP_OF_PAGE = ' '
    I_CALLBACK_HTML_END_OF_LIST = ' '
    I_STRUCTURE_NAME =
    I_BACKGROUND_ID = ' '
    I_GRID_TITLE =
    I_GRID_SETTINGS =
    IS_LAYOUT =
    IT_FIELDCAT = FIELDCATTAB[]
    IT_EXCLUDING =
    IT_SPECIAL_GROUPS =
    IT_SORT =
    IT_FILTER =
    IS_SEL_HIDE =
    I_DEFAULT = 'X'
    I_SAVE = ' '
    IS_VARIANT =
    IT_EVENTS =
    IT_EVENT_EXIT =
    IS_PRINT =
    IS_REPREP_ID =
    I_SCREEN_START_COLUMN = 0
    I_SCREEN_START_LINE = 0
    I_SCREEN_END_COLUMN = 0
    I_SCREEN_END_LINE = 0
    IT_ALV_GRAPHICS =
    IT_ADD_FIELDCAT =
    IT_HYPERLINK =
    IMPORTING
    E_EXIT_CAUSED_BY_CALLER =
    ES_EXIT_CAUSED_BY_USER =
    TABLES
    t_outtab = t_mchb
    EXCEPTIONS
    PROGRAM_ERROR = 1
    OTHERS = 2
    IF sy-subrc <> 0.
    MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
    WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
    ENDIF.
    endcase.
    endform.
    FORM usercommand2 USING r_ucomm LIKE sy-ucomm rs_selfield TYPE
    slis_selfield.
    CASE r_ucomm.
    WHEN '&IC1'.
    IF rs_selfield-sel_tab_field = 'T_MCHB-MATNR'.
    CALL FUNCTION 'ZALV2'
    EXPORTING
    CTU = 'X'
    MODE = 'E'
    UPDATE = 'A'
    GROUP =
    USER =
    KEEP =
    HOLDDATE =
    NODATA = '/'
    MATNR_001 = '200-200'
    KZSEL_01_002 = 'X'
    IMPORTING
    SUBRC =
    TABLES
    MESSTAB =
    SET PARAMETER ID 'RID' FIELD RMMG1-MATNR.
    CALL TRANSACTION 'MM03' and skip first screen.
    ENDIF.
    ENDCASE.
    CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
    EXPORTING
    i_callback_program = progname
    i_callback_user_command = 'USERCOMMAND3'
    it_fieldcat = fieldcattab[]
    TABLES
    t_outtab = t_mchb
    EXCEPTIONS
    program_error = 1
    OTHERS = 2.
    IF sy-subrc <> 0.
    MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
    WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
    ENDIF.
    endcase.
    ENDFORM.
    Thanks,
    Sankar M

  • Handling Enter ey of keyBoard

    hi all
    does any body know how to handle Enter key.
    infact in my OA framework pages when i press nothing happens..so ultimately i have to click the button on the page..
    i want to five some default behavior when i press enter ..
    pls give me an idea...
    thanking 4 ur kindness..
    regards,
    naveen

    i didnt get u ..
    why should i put this in processRequest ..why not in processFormRequest...
    see my controller code looks like
    /*===========================================================================+
    | Copyright (c) 2001, 2003 Oracle Corporation, Redwood Shores, CA, USA |
    | All rights reserved. |
    +===========================================================================+
    | HISTORY |
    +===========================================================================*/
    package igate.oracle.apps.icx.irep.client.server.webui;
    import oracle.apps.fnd.common.VersionInfo;
    import oracle.apps.fnd.framework.webui.OAControllerImpl;
    import oracle.apps.fnd.framework.webui.OAPageContext;
    import oracle.apps.fnd.framework.webui.beans.OAWebBean;
    import oracle.apps.fnd.common.MessageToken;
    import oracle.apps.fnd.framework.OAException;
    import oracle.apps.fnd.framework.webui.OAWebBeanConstants;
    import oracle.apps.fnd.framework.OAApplicationModule;
    import oracle.apps.fnd.framework.OAViewObject;
    import oracle.apps.fnd.framework.webui.OADialogPage;
    import oracle.apps.fnd.framework.webui.TransactionUnitHelper;
    import java.io.Serializable;
    * Controller for ...
    public class igteupdatedbmpCO extends OAControllerImpl
    public static final String RCS_ID="$Header$";
    public static final boolean RCS_ID_RECORDED =
    VersionInfo.recordClassVersion(RCS_ID, "%packagename%");
    * Layout and page setup logic for a region.
    * @param pageContext the current OA page context
    * @param webBean the web bean corresponding to the region
    String instancename;
    public void processRequest(OAPageContext pageContext, OAWebBean webBean)
    super.processRequest(pageContext, webBean);
    TransactionUnitHelper.startTransactionUnit(pageContext, "empUpdateTxn");
    instancename = pageContext.getParameter("InstanceName");
    pageContext.putTransactionValue("InstanceName", instancename);
    Serializable[] params = { instancename };
    OAApplicationModule am = pageContext.getApplicationModule(webBean);
    am.invokeMethod("initDetails1",params);
    * Procedure to handle form submissions for form elements in
    * a region.
    * @param pageContext the current OA page context
    * @param webBean the web bean corresponding to the region
    public void processFormRequest(OAPageContext pageContext, OAWebBean webBean)
    super.processFormRequest(pageContext, webBean);
    OAApplicationModule am = pageContext.getApplicationModule(webBean);
    if (pageContext.getParameter("Apply") != null)
    am.invokeMethod("apply");
    OAViewObject vo = (OAViewObject)am.findViewObjec("getcreatemappingVO1");
    TransactionUnitHelper.endTransactionUnit(pageContext, "empUpdateTxn");
    MessageToken[] tokens = { new MessageToken("INS_NAME",instancename)};
    OAException confirmMessage = new OAException("ICX",
    "ITE_IREP_INST_UPDATED", tokens,
    OAException.CONFIRMATION, null);
    pageContext.putDialogMessage(confirmMessage);
    pageContext.forwardImmediately("OA.jsp?page=/ite/oracle/apps/icx/irep/client/server/webui/igte_databasemapping",
    null,OAWebBeanConstants.KEEP_MENU_CONTEXT,null,null,true,OAWebBeanConstants.ADD_BREAD_CRUMB_NO);
    else if (pageContext.getParameter("Cancel") != null)
    am.invokeMethod("rollbackEmployee");
    TransactionUnitHelper.endTransactionUnit(pageContext, "empUpdateTxn");
    pageContext.forwardImmediately("OA.jsp?page=/ite/oracle/apps/icx/irep/client/server/webui/igte_databasemapping",
    null,
    OAWebBeanConstants.KEEP_MENU_CONTEXT,
    null,
    null,
    true, // retain AM
    OAWebBeanConstants.ADD_BREAD_CRUMB_NO);
    so my page has cancel and apply button..i want to give enter and apply button same functionality..
    can u give me an idea now...
    pls
    regards
    naveen

  • Enter key as Tab Key in a JTable

    How can I have the Enter Key act as a Tab Key in a JTable?

    thnx...but I already solved my problem. In case someone has the same problem:
    final InputMap im = table.getInputMap(JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT);
    final KeyStroke key = KeyStroke.getKeyStroke(KeyEvent.VK_ENTER, 0, false);
    im.put(key, "selectNextColumnCell");

  • Stop Enter key for acting in a JTable

    I am having some problems with scrolling because of the Enter key. I there a way to override or stop the enter key from acting in a JTable?

    The following code simulates a mouse click on a cell when enter is pressed. You should be able to change it to do nothing, or add other functionality.
    table = new JTable(model)
         protected void processKeyEvent(KeyEvent e)
               if ( e.getKeyCode() == KeyEvent.VK_ENTER
               &&   e.getID() == KeyEvent.KEY_PRESSED )
                   int column = table.getSelectedColumn();
                   int row = table.getSelectedRow();
                   Rectangle r = getCellRect(row, column, false);
                   Point p = new Point( r.x, r.y );
                   SwingUtilities.convertPointToScreen(p, table);
                    try
                         Robot robot = new Robot();
                         robot.mouseMove(p.x, p.y );
                         robot.mousePress(InputEvent.BUTTON1_MASK);
                         robot.mouseRelease(InputEvent.BUTTON1_MASK);
                         robot.mousePress(InputEvent.BUTTON1_MASK);
                         robot.mouseRelease(InputEvent.BUTTON1_MASK);
                         robot.mouseMove(0, 0 );
                    catch (Exception e2) {}
               else
                   super.processKeyEvent(e);
    };

  • JFormattedTextField as CellEditor in JTable & Enter key question

    Hi all,
    I have a cell editor (quite complicated) containing JFormattedTextField; for the description of the problem we can simplify it as:
    class Editor extends AbstractCellEditor implements TableCellEditor {
            JFormattedTextField ftf = new JFormattedTextField();
            public Object getCellEditorValue() {
                return ftf.getText();
            public Component getTableCellEditorComponent(JTable table, Object value, boolean isSelected, int row, int column) {
                return ftf;
        }The problem is when I use this cell editor in JTable, and change the value in formatted text field and try to confirm change by Enter key, nothing happens (cursor stays in formatted text field).
    Note when I use JTextField instead of JFormattedTextField in cell editor, Enter key "confirms" new value and jumps to following cell in table (according JTable binding). So I guess JFormattedTextField "consumes" the Enter stroke in some way.
    I want to achieve the same behavior on Enter key in case of JFormattedTextField as in case of JTextField in cell editor.
    I have searched the forum, tried a lot, but was unable to find solution for such a simple problem ... probably I missed something ...
    Thanks a lot, Pepek

    The cell editor is not applied in your code (the question is what my.setCellEditor() does but it is another topic - you can find it on this forum). Use e.g.:
    public class Untitled1 extends JFrame {
        public Untitled1() {
            JPanel panel = new JPanel();
            JTable my = new JTable(5,5);
            my.setDefaultEditor(Object.class, new Editor()); //or my.getColumnModel().getColumn(0).setCellEditor(new Editor()); //just for first column
            panel.add(my);
            this.add(panel);
            pack();
            setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
            setVisible(true);
        class Editor extends AbstractCellEditor implements TableCellEditor {
            JFormattedTextField ftf = new JFormattedTextField();
            public Object getCellEditorValue() {
                return ftf.getText();
            public Component getTableCellEditorComponent(JTable table, Object value, boolean isSelected, int row, int column) {
                ftf.setBackground(Color.YELLOW); // just to visually confirm which editor is used
                return ftf;
        public static void main(String[] args) {
            Untitled1 untitled1 = new Untitled1();
    }Therefore you couldn't find any difference - you used the same cell editor in both cases.

  • Enter key to act like tab key in JTable

    I have programmed a JTable application. I want that if I press 'Enter' key in the JTable cell, the cell at right side may be selected after validating input. Similarly, when I press 'Enter' in the right most cell, the first cell of the next row may be selected after validating input.
    In other words, I like 'Enter' key to behave as forward navigational key in JTable cells like 'Tab' key, however, after validating input.
    The following is the piece of code which is not working for me. Though, it changes selection border to the next cell on pressing enter, but the focus is not shifted and editing remains in the current cell.
    //voucherTable is a JTable object with three columns.
    Action moveForward = new AbstractAction() {
    public void actionPerformed(ActionEvent e) {
    int r=voucherTable.getSelectedRow();
    int c=voucherTable.getSelectedColumn();
    if(c==2){
    c=-1;
    r+=1;
    voucherTable.changeSelection(r,c+1,false,false);
    voucherTable.getInputMap().put(KeyStroke.getKeyStroke
    (KeyEvent.VK_ENTER,0),"moveForward");
    voucherTable.getActionMap().put("moveForward",
    moveForward);
    Kindly advise me to solve the problem.
    Thanks.
    Mujjahid

    KeyStroke tab = KeyStroke.getKeyStroke(KeyEvent.VK_TAB, 0);
    KeyStroke enter = KeyStroke.getKeyStroke(KeyEvent.VK_ENTER, 0);
    InputMap im = table.getInputMap(JTable.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT);
    im.put(enter, im.get(tab));

Maybe you are looking for