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
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();
}
}
});