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

Similar Messages

  • 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 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);
    }

  • 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));

  • 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!

  • Remove the Enter key binding from a JPopupMenu

    Hi,
    Does anyone know how to remove the Enter key binding from a JPopupMenu?
    So when the popupmenu is showing and you type Enter, nothing should happen and the menu should stay where it is.
    I have tried:
    popup.getActionMap().put("enter", null);
    popup.getInputMap().put(KeyStroke.getKeyStroke(KeyEvent.VK_ENTER, 0), "enter");but the popup always disappears.
    Any ideas?
    Cheers,
    patumaire

    First of all, that is not the proper way to "remove" a key binding. Read the Swing tutorial on [How to Use Key Bindings|http://java.sun.com/docs/books/tutorial/uiswing/misc/keybinding.html#howto] for more information.
    However, we still have a couple of problems:
    a) the input map is dynamically built as the popup menu is displayed
    b) the input map is built for the root pane, not the popup menu
    The following seems to work:
    popup.show(...);
    InputMap map = getRootPane().getInputMap(JTable.WHEN_IN_FOCUSED_WINDOW);
    map.put(KeyStroke.getKeyStroke("ENTER"), "none");
    KeyStroke[] keys = map.allKeys();
    for (int i = 0; i < keys.length; i++)
         KeyStroke key = keys;
         Object action = map.get( key );
         System.out.println(key + " : " + action);

  • Escape key in jtable while editing

    I am trying to unregister the escape key from the jtable when it is in an editing mode. The field in an editable mode is a JTextField. I tried:
    this.getInputMap().remove(KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0));I also tried removing it from the JTextField in MyCellEditorObject (which extends DefaultCellEditor)
    But the escape key does not seem to be in either of these components when I do:
    KeyStroke[] ks = this.getInputMap().allKeys();
    if(null == ks)
        System.out.println("null ks........................");
    else
        for (int i = 0; i < ks.length; i++)
            System.out.println(ks.toString());
    Once I get this figured out I need to add and remove other keys to whatever object is handling the events.
    Does anyone know what object is handling the escape key in the JTable while it is in an editing state using a JTextField?

    Well, for others who may have the same problem this is what I found so far:
    The jtable.getInputMap() will always return null (hardcoded in BasicTableUI). To get the input map one has to put:
    jtable.getInputMap(JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT)
    Then
    KeyStroke[] ks = this.getInputMap(JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT).allKeys();
    returns keys in the input map and the parent input map....(.keys() will exclude the keys in the parent input map).
    For the JTable all the keys are registered in the parent inputMap.
    m_table.getInputMap(JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT).getParent().remove(KeyStroke.getKeyStroke(KeyEvent.VK_ALPHANUMERIC, 0));
    m_tablegetInputMap(JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT).getParent().remove(KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0, false));
    m_table.getInputMap(JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT).getParent().put(KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0, true), "quitRelease");
    m_table.getInputMap(JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT).getParent().put(KeyStroke.getKeyStroke(KeyEvent.VK_F9, 0), "actionMApKeyObject");
    m_table.getActionMap().put("quitRelease", new QuitAction());
    m_table.getActionMap().put("send", new SendAction());
    private class QuitAction  extends AbstractAction
        public void actionPerformed(ActionEvent ae)
           //do quit cellediting stopped? yes then press quit btn no thenstop ...
    private class SendAction  extends AbstractAction
        public void actionPerformed(ActionEvent ae)
           //do send
    }I still would like to know more about the input maps...and the parent input map???
    As well as the ActionMaps all introduced in 1.3.
    Does anyone know of any URLs or books that contain good explanations and samples
    (I have not found any)...
    I am also interested in how this could be applied more globally
    like the enter key pressing all buttons in my application.
    Or having text fields respond to keyReleased rather than pressed.

  • Recognize ENTER hit on JTable after cell edit is done

    Hello,
    I'm trying to find a way to detect a key press (specifically, Enter key) after editing a value on a JTable. That is, when I double click on a cell in my table, edit the value and press enter after the editing is done, I want to be able to detect pressing the enter. Adding a normal keyListener to the JTable object won't do it. So I'm trying to find a new way. Please help me out!
    Here's my SSCCE:
    import java.awt.event.KeyAdapter;
    import java.awt.event.KeyEvent;
    import javax.swing.JFrame;
    import javax.swing.JScrollPane;
    import javax.swing.JTable;
    public class MyTable extends JTable {
         JTable table;
         public MyTable(Object[][] data, Object[] columnNames)
              JFrame frame = new JFrame("My Table");
              table = new JTable(data, columnNames);
              JScrollPane scrollPane = new JScrollPane(table);
              frame.getContentPane().add(scrollPane);
              frame.setSize(100, 100);
              frame.setVisible(true);
              table.addKeyListener(new KeyAdapter()
                   public void keyPressed(KeyEvent e)
                        if(e.getKeyChar()==KeyEvent.VK_ENTER)
                             System.out.println("Key Pressed");
         public static void main(String[] args) {
              // TODO Auto-generated method stub
              Object [][]data = {{"item1"},{"item2"},{"item3"},{"item4"},{"item5"}};
              String []columnNames = {"ITEMS"};
              MyTable table = new MyTable(data, columnNames);
    }Message was edited by:
    programmer_girl

    First of all you don't use a KeyListener to check for KeyEvents on a compponent. You use "Key Bindings" and Actions:
    http://java.sun.com/docs/books/tutorial/uiswing/misc/keybinding.html
    When you are "editing" a cell then focus is on the edtitor used by cell editor. For a cell containing Strings a JTextField is used. Since a JTextField supports an ActionListener all you need to do is get the JTextField and add an ActionListener to the text field. You can use the getDefaultEditor(...) method of JTable and cast the editor to a DefaultCellEditor. From there you can then get the editing component.
    Of course the question is why are you specifically worried about the enter key? What if the user tabs to the next cell or uses the mouse to click on a different cell. There is more than one way to finish editing a cell.

  • Disabling RETURN key in jTable

    Hi,
    I have a readonly jTable with some buttons underneath it.
    If i press the RETURN key it changes the focus to the next row in the table. Instead of this, i want the RETURN key to activate one of the buttons.
    I tried to disable the ENTER key action on the jTable by putting :
    table.getInputMap().put(KeyStroke.getKeyStroke(KeyEvent.VK_ENTER,0),"none");However, this doesn't give the desired result.
    Do i need to specify another keycode to disable the RETURN key or do i miss something else ?
    Thx for any help on this.
    Roger.

    Did you specify what action to take with the line of code you posted?
              Action none = new AbstractAction() {     
                   public void actionPerformed(ActionEvent e ){
                           //do whatever action you want taken here
                    pane.getInputMap().put( KeyStroke.getKeyStroke( KeyEvent.VK_ENTER, 0 ), "none" );

  • HOW to simulate the enter key???

    Hi , I have a jTable ,and i want that by leaving a specific
    cell ,to perform the same action that the enter key does!
    when im leaving my specific cell the following function is being called:
    public void editingStopped(ChangeEvent e) {
    //here I want to simulate the enter-key's action
    HOW to simulate the enter key???
    10x in advance
    Nir.
    p.s. My initial problem was that when i left my specific
    cell (the cell is editable combo box), an edited words
    which were written by me vanished , and when i get back to that cell the edited word showed again!!!
    when i pressed the enter key the edited word were stable in the cell!!!
    when I chose a word from the combo evrything was ok!!
    so if any one can solve me that problem ill be appreciate.
    thanks Nir

    yourActionListener.actionPerformed(new ActionEvent(yourCell))
    I am not sure about the constructor of actionevent.
    you could try if setText(getText()) produces a good result

  • How to refresh changed data in a plannable template with the Enter Key

    Hi,
    The situation I face is as follows.
    Integrated Planning is being implemented as a tool for budgeting. The user changes a value in a plannable cell on the portal and wishes to see the new updated data by pressing ENTER. Currently we have provided a REFRESH button so that the user gets the desired result.
    Is it possible to see the updated value by pressing ' ENTER' and if so , whats the way around to do it.
    thanks in advance.
    Jaya

    Hey guys,
    I'm interested too in this solution. In BPS there is an additional function described in the HowTo Paper HowTo run planning functions on save and other events
    Now I'm looking for this possibility in IP as well in excel-based IP and web-based IP. For example a copy function should be executed automatically when pushing the enter key.
    Thanks a lot!
    Clemens

  • Table Control[Accept Input Only] - "ENTER" Key

    Hi Folks,
    I'm reviving this unanswered thread in relation to table control: when the user press enter, all the values entered disappear.
    [url]Re: Table control (Enter key)[url]
    I have a table control that accepts "ONLY" input, meaning to say, there will be no pre-loading of data in the PBO, so it will loop through the table control itself instead of looping from an internal table.
    Issue: Whenever I press "ENTER" in any column/row of my table control, ALL the values I entered disappear.
    PBO:
    PROCESS BEFORE OUTPUT.
      MODULE CLEAR_OKCODE.
      MODULE LOAD_TABLECTRL.
      LOOP WITH CONTROL TC_DATA.
        MODULE READ_DATA.
      ENDLOOP.
    module READ_DATA output.
      READ TABLE T_DATA INTO WA_DATA INDEX TC_DATA-current_line.
      data : line_count type i.
      "to increase the number of lines in table control dynamically
      describe TABLE t_data lines line_count.
      TC_DATA-lines = line_count + 10.
    endmodule. 
    PAI:
    PROCESS AFTER INPUT.
      LOOP WITH CONTROL TC_DATA.
        MODULE MODIFY_DATA.
      ENDLOOP.
    module MODIFY_DATA input.
    WHEN 'CREATE'.
      "subroutines are here, etc.
    WHEN 'DELETE'.
    WHEN 'BACK'.
      LEAVE TO SCREEN 0.
    endmodule.
    In my ABAP Debug, the value of SY-UCOMM is BLANK whenever I press Enter.
    Thanks.

    Hi
    Your code seems to be rght only the MODIFY statament is useless:
    module READ_DATA output.
      READ TABLE T_ID_CHECK INTO WA_ID_CHECK INDEX TC_ID-current_line.
      IF SY-SUBRC EQ 0.
        ZQID_CHECK-WERKS = WA_ID_CHECK-WERKS.
        ZQID_CHECK-MATNR = WA_ID_CHECK-MATNR.
        ZQID_CHECK-LICHA = WA_ID_CHECK-LICHA.
        ZQID_CHECK-LIFNR = WA_ID_CHECK-LIFNR.
      ELSE.
        CLEAR ZQID_CHECK.
      ENDIF.
    endmodule.
    Now before LOOP of PBO try to set the lines of table control to be display, I've created this report on my system and it works fine:
    .CONTROLS T_CTRL TYPE TABLEVIEW USING SCREEN 100.
    DATA: BEGIN OF ITAB OCCURS 0,
              WERKS LIKE MARC-WERKS,
              MATNR LIKE MARC-MATNR,
              LIFNR LIKE LFA1-LIFNR,
          END   OF ITAB.
    DATA: WA LIKE ITAB.
    START-OF-SELECTION.
      DO 4 TIMES.
        ITAB-WERKS = '5010'.
        ITAB-MATNR = '1234567890'.
        ITAB-LIFNR = '0000000001'.
        APPEND ITAB.
      ENDDO.
      CALL SCREEN 100.
    PROCESS BEFORE OUTPUT.
      MODULE SET_T_CTRL.
      LOOP WITH CONTROL T_CTRL.
        MODULE READ_DATA.
      ENDLOOP.
    PROCESS AFTER INPUT.
      LOOP WITH CONTROL T_CTRL.
        MODULE MODIFY_DATA.
      ENDLOOP.
    MODULE SET_T_CTRL OUTPUT.
      DESCRIBE TABLE ITAB LINES T_CTRL-LINES.
    ENDMODULE.                 " SET_T_CTRL  OUTPUT 
    MODULE READ_DATA OUTPUT.
      READ TABLE ITAB INDEX T_CTRL-CURRENT_LINE.
      IF SY-SUBRC = 0.
        MOVE-CORRESPONDING ITAB TO WA.
      ELSE.
        CLEAR WA.
      ENDIF.
    ENDMODULE.                 " READ_DATA  OUTPUT
    MODULE MODIFY_DATA INPUT.
      MODIFY ITAB FROM WA INDEX T_CTRL-CURRENT_LINE.
      IF SY-SUBRC NE 0.
        CHECK NOT WA IS INITIAL.
        APPEND WA TO ITAB.
      ENDIF.
    ENDMODULE.                 " MODIFY_DATA  INPUT

Maybe you are looking for