I made jFrame in netbeans with 1 jTable, 1 jTextField, and 1 Button. I put these codes inside jButtonActionPerformed.
String kar="";
table.setValueAt('a', 0, 0);
table.setValueAt('b', 1, 0);
table.setValueAt('c', 2, 0);
table.setValueAt('d', 0, 1);
table.setValueAt('e', 1, 1);
table.setValueAt('f', 2, 1);
for(int i=0;i<3;i++){
for(int j=0;j<3;j++){
String ar = (table.getValueAt(i, j).toString());
kar+=ar;
}
}
a.setText(kar);
So, I set the value of table as above, and I want to display it in textfield as a sentence .. So the output should be "abcdef". But I got nothing in my textfield. Can anyone help me solve this problem?
I'm pretty new at this..So I hope u guys can explain with something that's easy to understand.
This line:
String ar = (table.getValueAt(i, j).toString());
will throw a NullPointerException when j = 2 change the limit on j in the for loop to j<2 like this:
for(int i=0;i<3;i++){
for(int j=0;j<2;j++){
String ar = (table.getValueAt(i, j).toString());
kar+=ar;
}
}
In the future, check the output pane to see if any Exceptions are thrown and/or run in the debugger to make sure it executes your functions all the way to the end.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.