简体   繁体   English

在运行时向JTable追加新行

[英]Appending a new row to a JTable at runtime

I am developing a Java application that uses a JTable. 我正在开发使用JTable的Java应用程序。 I want to allow the user to enter data in a JTable that can later be printed or saved. 我想允许用户在JTable中输入数据,以后可以打印或保存该数据。 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. 问题是:假设用户输入了一些数据,并且光标位于表中行的最后一个单元格上(我已经上传了一个图像,假设光标位于突出显示的单元格上)。这样,当用户按下Enter键(键盘按钮)时,应用程序将在表中添加/添加一个新行,以便用户可以填写其他数据。 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);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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