Extract values from given Form

后端 未结 3 2057
后悔当初
后悔当初 2021-01-24 01:53

I want to extract values on clicking the button save. Extract values from JTextField and JTable rows and columns. Just want a rough idea h

3条回答
  •  小蘑菇
    小蘑菇 (楼主)
    2021-01-24 02:25

    In addition to invoking textField.getText(), you can obtain a reference to your table's model and iterate over the values using getValueAt():

    JButton save = new JButton("Save");
    save.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            System.out.println(textField.getText());
            TableModel model = table.getModel();
            for (int r = 0; r < model.getRowCount(); r++) {
                for (int c = 0; c < model.getColumnCount(); c++) {
                    System.out.print(model.getValueAt(r, c) + " ");
                }
                System.out.println();
            }
        }
    });
    

提交回复
热议问题