How to add row of data to Jtable from values received from jtextfield and comboboxes

后端 未结 3 388
感情败类
感情败类 2021-02-01 23:57

I have a JFrame Form which has JTextFields, JCombobox etc. and I am able to receive those values to variables and now I want to add the re

3条回答
  •  鱼传尺愫
    2021-02-02 00:31

    you can use this code as template please customize it as per your requirement.

    DefaultTableModel model = new DefaultTableModel();
    List list = new ArrayList();
    
    list.add(textField.getText());
    list.add(comboBox.getSelectedItem());
    
    model.addRow(list.toArray());
    
    table.setModel(model);
    

    here DefaultTableModel is used to add rows in JTable, you can get more info here.

提交回复
热议问题