• Post Reply Bookmark Topic Watch Topic
  • New Topic

Displkaying Nested Objects in JTable -Please Help

 
Kinu Kanwar
Ranch Hand
Posts: 33
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have a class A that has a structure

Class A
{
String name ;
B[] b ; ;
}

class B
{
String child1 ;
String child2 ;
}

Now the problem is that I need to show object A in table structure. class A has an array of class B , the sample data could be like that i-e class A has array of B that is of length 3.

A.name b.child1 b.child2
ZZZ xxx 111
ZZZ yyy 222
ZZZ rrr 333

My Funstion getValueAt(defined in Table model) is

public Object getValueAt(int row, int col)
{
switch (col)
{
case 0:
return ( object_of_A[row]).getName();

case 1:
return ( object_of_A[row]).getB();
// return "Dummy Data"
}
}

This compiles fine but problem is that whatever you return from getValueAt() , it is displayed in column like if I remove comments from "Dummy Data" , it would be printed in whole 2nd column.

But getB() return array of B and then I get null pinter excpetion.

Can some oen tell me that the way to print nested objects in table structure.

Any help is appreciated/

Thanks

Kinu
 
Scott Delap
author
Ranch Hand
Posts: 73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sounds like you might want to use a tree table instead.
http://java.sun.com/products/jfc/tsc/articles/treetable1/

Scott Delap
ClientJava.com
Desktop Java Live
 
Kinu Kanwar
Ranch Hand
Posts: 33
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
No . I guess it wont help as I need simple table as output

Kinu
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!