Extract values from given Form

后端 未结 3 2055
后悔当初
后悔当初 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:08

    From JTable use getValueAt method to retrieve the value.

    From JTextField use textField.getText() as stated by @Abu

    0 讨论(0)
  • 2021-01-24 02:17

    From the jtextfield you can invoke the getText method to get the contents of the textfield in the form of a String like:

    String myString = textField.getText();
    
    0 讨论(0)
  • 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();
            }
        }
    });
    
    0 讨论(0)
提交回复
热议问题