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
From JTable
use getValueAt method to retrieve the value.
From JTextField
use textField.getText()
as stated by @Abu
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();
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();
}
}
});