Results 1 to 3 of 3
  1. #1
    usha is offline Member
    Join Date
    Oct 2010
    Rep Power

    Default how to add keyListener event to JTable

    I added a keyListener event to one JTable "table1", and i implemented the method keyReleased. now my requirement is when i edit row data of table1 and when i press enter key, one new row should added to another JTable "table2". i implemented the code as below its working perfectly when i press enter key first time and one row also added to table2 ,but when i press enter key second time, the corresponding function calling two times and two rows are added into table2 .

    i implemented the code as follows

    jTable1.addKeyListener(new java.awt.event.KeyAdapter() {

    public void keyReleased(java.awt.event.KeyEvent ke){

    javax.swing.table.DefaultTableModel d1=(javax.swing.table.DefaultTableModel) tModel();
    d1.addRow(new Object[]{(String)jTable1.getValueAt(jTable1.getRowCount()-1,0)});

    please help me.

    Thanks in advance,
    Last edited by usha; 10-23-2010 at 12:56 PM.

  2. #2
    DarrylBurke's Avatar
    DarrylBurke is offline Forum Police
    Join Date
    Sep 2008
    Madgaon, Goa, India
    Rep Power


    Can't know the source of your stated problem without an SSCCE (Short, Self Contained, Compilable and Executable) example, but why on earth are you invoking updateUI() ? Did you even take a look at the documentation for the method?
    Notification from the UIManager that the L&F has changed. Replaces the current UI object with the latest version from the UIManager.

    Another note: Wherever possible, use key bindings, not a KeyListener.

    Last edited by DarrylBurke; 10-23-2010 at 02:20 PM.

  3. #3
    Horcrux7 is offline Member
    Join Date
    Sep 2010
    Rep Power


    I think you have register the key listener 2 times. Add a debug out on the place where you register the listener.
    Volker Berlin

Similar Threads

  1. keyListener not doing anything
    By imorio in forum AWT / Swing
    Replies: 10
    Last Post: 08-17-2010, 11:46 PM
  2. Problem with KeyListener in Jtable
    By sandeepsai17 in forum New To Java
    Replies: 0
    Last Post: 06-30-2009, 11:14 AM
  3. KeyListener - Is this what I need?
    By dbashby in forum New To Java
    Replies: 26
    Last Post: 04-18-2009, 05:14 PM
  4. KeyListener Example
    By Java Tip in forum SWT Tips
    Replies: 0
    Last Post: 07-11-2008, 05:46 PM
  5. how to add a KeyListener
    By leonard in forum New To Java
    Replies: 1
    Last Post: 08-06-2007, 05:44 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts