My problem is this. I have a table on my first JFrame and now I want the data on my first table to be duplicated on the table of my second JFrame. I'm using GUI, I have 2 JFrames, both JFrames have tables and i want both tables to display same data.
I have come up to this solution but I don't know how to set the data on my second table.
This is the code:
public Object[][] getTableData (JTable table) {
TableModel dtm = table.getModel();
int nRow = dtm.getRowCount(), nCol = dtm.getColumnCount();
Object[][] tableData = new Object[nRow][nCol];
for (int i = 0 ; i < nRow ; i++)`enter code here`
for (int j = 0 ; j < nCol ; j++)
tableData[i][j] = dtm.getValueAt(i,j);
return tableData;
}
How do I solve the problem?
To make it more clear. ill attach photo
my second jframe is just a summary of what is being entered in first JFrame. that is the reason why i use 2 JFrames.
i have 2 JFrame forms. in First JFrame Form i have this Code, i tried to modify the code above a bit.
public Object[][] getEquipTableData () {
TableModel dtm = equipmentBorrowTable.getModel();
int nRow = dtm.getRowCount(), nCol = dtm.getColumnCount();
tableDataE = new Object[nRow][nCol];
for (int i = 0 ; i < nRow ; i++)
for (int j = 0 ; j < nCol ; j++)
tableDataE[i][j] = dtm.getValueAt(i,j);
return tableDataE;
}
and then at the second JFrame i have this partof code
public StudentSumarry() {
StudentModeDashboard SMD = new StudentModeDashboard();
String[] columnNames = {"Employee 1", "Employee 2", "Employee 3", "Employee 4"};
Object[][] firstTableData = SMD.getEquipTableData();
initComponents();
equipmentBorrowTable2.setModel(new DefaultTableModel(firstTableData, columnNames));
}
i instantiate my JFrame1 on JFrame2 to use the method getEquipTableData() on JFrame1. IDK if what im doing is right.