I am working in NetBeans IDE, language Java, the main class is JFrameForm.
I have a jTable tab with just one row and one column, button and jTextField en, where type should be integers. The input is variable n.
I need to create matrix with n rows and n columns. So n x n dimension of matrix as a jTable.
After click on the button, variable n will be saved as dimension and loop will start add the column and row till n.
The code is following:
private void sendMouseClicked(java.awt.event.MouseEvent evt) {
DefaultTableModel model = (DefaultTableModel) tab.getModel();
String sn=en.getText();
int n=Integer.valueOf(sn);
for(int j=2;j<=n;j++){
model.addColumn(null); // I know this is wrong
model.addRow(new Object[]{test.getText()+j});
test.setText(test.getText()+j);
}
}
I got error
Exception in thread "AWT-EventQueue-0" java.lang.ArrayIndexOutOfBoundsException: 1
The cells should be empty.
Please help me to input the column. What is object there?