简体   繁体   中英

Appending a new row to a JTable at runtime

I am developing a Java application that uses a JTable. I want to allow the user to enter data in a JTable that can later be printed or saved. The issues is: Suppose the user has entered some data and the cursor is on the last cell of the row in a table (I have uploaded an image-suppose the cursor is on the highlighted cell).How do I make it in such a way that when a user presses the Enter Button(Keyboard button) the application will add/append a new row that is empty to the table so that the user can fill in other data. Attachment

Try this...

  JTable table = new JTable();
  DefaultTableModel tblModel = new DefautlTableModel(0,0);

  table.setModel(tblModel);



  //an action or click then you should run this code


  tblModel.addRow(new Object[]{""}); 
    DefaultTableModel tbm = (DefaultTableModel) jTable1.getModel();
    Vector rowData = null;
    tbm.addRow(rowData);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM