Hi everyone, I'm a beginner in Java and I'm trying to divide a Jtable into two auther Jtables.Thank you for your help.
public String Ex(JTable table, JTable tab2, JTable tab3) { String message = "Erreur"; DefaultTableModel modele = new DefaultTableModel(); tab2.setModel(modele); DefaultTableModel modele1 = new DefaultTableModel(); tab3.setModel(modele1); int NumeroLigne = table.getRowCount(), NumeroColonne = table.getColumnCount(); int t = 0; if (NumeroLigne-1 % 2 == 0) { t = NumeroLigne / 2; } else{ t=(NumeroLigne/2)+1;} for (int i = -1; i < t; i++) { int r=0; r=i+1; Object Row[]=new Object[r]; modele.addRow(Row); for (int j = 0; j < NumeroColonne; j++) { if (i ==-1) { modele.addColumn(String.valueOf(table.getColumnName(j))); } else { modele.setValueAt(table.getValueAt(i, j), i, j); } }} for (int i = t; i < NumeroLigne; i++) { Object Row1[]=new Object[i]; modele1.addRow(Row1); for (int j = 0; j < NumeroColonne; j++) { if (i ==t) { modele1.addColumn(String.valueOf(table.getColumnName(j))); } else { for(int r=1;r<NumeroLigne;r++){ modele1.setValueAt(table.getValueAt(i,j), i, j); } } } } message = "good!!!"; return message;} }
Exception in thread "AWT-EventQueue-0" java.lang.ArrayIndexOutOfBoundsException: 11 >= 2