• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Displaying Data

 
Christian Garcia
Ranch Hand
Posts: 77
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Can anyone explain to me that approach he/she took to display the data in the Table? I have code returning DataInfo objects and have a custom TableModel for data display. The question that I haven't found a sound answer to is how the data should be taken from each DataInfo object and then populated in the table?
 
Mark Spritzler
ranger
Sheriff
Posts: 17278
6
IntelliJ IDE Mac Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
In my TableModel I created a method called
private void setDataArray(DataInfo[] records, int fieldCount)
I call this method from the constructor of the table model. In this Array I create a 2 dimensional array. I loop through the DataInfo array and assign the values to the 2 dim array, and there you go.
Mark
 
Christian Garcia
Ranch Hand
Posts: 77
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Mark,
So, if I use code similiar to this:

The TableModel will be able to populate a row with the data contained in myArray[0][0] ?
 
Mark Spritzler
ranger
Sheriff
Posts: 17278
6
IntelliJ IDE Mac Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes that is the basic idea. You are transforming the DataInfo array into a two dimensional array that a DefaultTableModel already knows how to handle, in one three line method.
Mark
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic