am trying fill jtable form existing object[][][] array
problem data or containing [ljava.lang.object;@
instead of (integer) data though mad system.out.println("")
print data before putting them jtable same problem ; here code next small shot screen , thanx help.
import java.awt.component; import javax.swing.jframe; import javax.swing.jscrollpane; import javax.swing.jtable; public class gass extends jframe { string title[] ={"box", "weight", "priority"}; public gass() { int nb=interface1.bnumber; object[][][] data = new object[nb][nb][nb]; int e1=0, e2=0; (int i=0;i<nb;i++) { data[i][0][0] = i+1; e1 = (int) (math.random() * 100); data[0][i][0] = e1; e2 = (int) (math.random() * 10); data[0][0][i] = e2; } (int j=0;j<nb;j++) { system.out.println("*"+data[j][0][0]+"*"+data[0][j][0]+"*"+data[0][0][j]+"*"); } jtable table = new jtable(data, title); component add = this.getcontentpane().add(new jscrollpane(table)); this.setvisible(true); table.setpreferredscrollableviewportsize(table.getpreferredsize()); this.setsize(800,400); } }
another problem wrong data in first cases of object array ***data[0][0][0] = wrong information !!***
next, link description of output of small application , lot help
the jtable constructor takes object[][]
argument.
this array array of rows. data[i]
row, array of columns.
and each row in array array of columns. each column (data[i][j]
) should contain data displayed in 1 cell of jtable.
in case, data array. since there no specific renderer associated object arrays, tostring()
method of array used display array in cell. , array's tostring() method returns [ljava.lang.object;@
.
you should tell display in each cell, better answer, explaining should do.
edit:
given want display, need two-dimensional array:
object[][] data = new object[nb][3]; // nb rows, 3 columns (int row = 0; row < nb; row++) { data[row][0] = row + 1; // first column: row number data[row][1] = math.random(100); // second column: weight data[row][2] = math.random(10): // third column: priority }
Comments
Post a Comment