我需要一些帮助理解不被填充的ArrayList为什么,JTable中的TextArea在java中
我想传递一个的JTable,在JFrame到一个JTextArea taht存储的信息是另一个JFrame的,我curently有下面的代码,但由于某些原因,信息不被通过,它保持空
我不希望任何人做我的HW我,我只需要在正确的方向指出,
这里我到目前为止的守则。
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;
}
那是在第一次的JFrame和按钮的第二JFrame的点击,我有
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));
}
}
我会apriciate任何帮助,您可以给。
THX提前.....
修复....
THX的帮助固定它像这样,
Edit ed = new Edit(extractTableInfo());
ed.setVisible(true);
是在第一帧,并在第二帧我这样做
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)));
}
而且它的工作是这样
遵守命名约定是一种好习惯。在Java中,惯例是只有类名有第一个大写字母。因此,你的'TableInformation'应该被称为'tableInformation'。遵循这些约定会增加代码的可读性 - 例如,乍一看,TableInformation.get(i)看起来像是一个静态的调用。 – 2011-12-19 11:42:10