I need some help understanding why the ArrayList is not being populated,
I am trying to pass information Stored in a jTable that is on a JFrame to a JTextArea taht is on another JFrame, i curently have the following code but for some reason the information is not being passed, it stays Empty
I dont want Anyone to do my HW for me i just need to be pointed in the right direction,
here is the Code i did so far.
public ArrayList<String> extractTableInfo() {
DefaultTableModel model = (DefaultTableModel) jTable1.getModel();
int nRow = model.getRowCount(), nCol = model.getColumnCount();
ArrayList<String> extractedInfo = new ArrayList<String>();
String rowInfo = "";
for (int i = 0; i < nRow; i++) {
for (int j = 0; j < nCol; j++) {
rowInfo = rowInfo + (String) model.getValueAt(i, j);
}
extractedInfo.add(rowInfo);
}
return extractedInfo;
}
Thats in the First JFrame and in the second JFrame on button Click i have
private void jButton3ActionPerformed(java.awt.event.ActionEvent evt) {
Generate_Teams gt = new Generate_Teams();
ArrayList<String> TableInformation = new ArrayList<String>();
for(int i =0; i < gt.extractTableInfo().size(); i++){
TableInformation.add(gt.extractTableInfo().get(i));
}
for (int i = 0; i < TableInformation.size(); i++) {
jTextArea1.append(TableInformation.get(i));
}
}
i would apriciate any help you can give.
Thx in advance…..
Fix….
Thx for your help fixed it like this,
Edit ed = new Edit(extractTableInfo());
ed.setVisible(true);
that is in the First Frame and in the second frame i did this
private ArrayList<String> infogot = new ArrayList<String>();
public Edit(ArrayList<String> getinfo)
{
initComponents();
this.infogot = getinfo;
}
for (int i = 0; i < infogot.size(); i++) {
jTextArea1.append(String.valueOf(infogot.get(i)));
}
And it worked like this
Try debugging your code. It might help adding print statements to check if the ArrayList returned by the
extractTableInfomethod contains the contents of the table.Also, the loop below could be improved:
It looks like whenever you call extractTableInfo you are creating a new ArrayList and populating it from the table over and over again.
Instead use:
Or even better, use: