Reputation: 35
I'm trying to create a table , and i'm using the setValueAt() to add the values to my table.
Some of my code :
int nalt=1+((altmax-altmin)/incr);
tabela=new JTable(new String[nalt][6],colunas);
for(int i=0;i<=(nalt-1);i=i){
for(int j=altmin;j<=altmax;j=j+incr){
tabela.setValueAt(""+j, i, 0);
i=i+1;
}
The thing is , if i leave the value = (""+j) it works fine, but if i leave only (j) i get alot of errors.
i tried to do this:
int nalt=1+((altmax-altmin)/incr);
tabela=new JTable(new String[nalt][6],colunas);
for(int i=0;i<=(nalt-1);i=i){
for(int j=altmin;j<=altmax;j=j+incr){
Object ty=new Integer(j);
tabela.setValueAt(ty, i, 0);
i=i+1;
}
and this :
int nalt=1+((altmax-altmin)/incr);
tabela=new JTable(new String[nalt][6],colunas);
for(int i=0;i<=(nalt-1);i=i){
for(int j=altmin;j<=altmax;j=j+incr){
tabela.setValueAt(new Integer(j), i, 0);
i=i+1;
}
but still i got alot of errors . i could do the first way , leaving (""+j) , but i will need that value , and i'm getting trouble converting that object to int . If you could help me trying to understand why i'm getting errors that would be nice. Or help me converting that object to a int . I mean i will need to use the .getValueAt(...) and i think i'm getting troubles to converting because the obect is (""+number) , or maybe im wrong .
Thanks
Upvotes: 0
Views: 89
Reputation: 1545
The problem is that you setup your JTable with a String array: new JTable(new String[nalt][6],colunas);
but then you try to add an integer: tabela.setValueAt(new Integer(j), i, 0);
. The solution is to set up your table with an integer array in the first place:
tabela=new JTable(new Integer[nalt][6],colunas);
Upvotes: 1