setText label for objects

I have an array of objects whose data i trying to display using jlabels

for(int i=0;i<3;i++)
{
for(int j=0;j<2;j++)
{
setText(obj[i][j].getName())
setText(obj[i][j].getSchool());
etc...
}
add it to the panel...
add to container..
}
my problem is that the labels are not getting printed. The only thing getting printed is teh last element of the object.
;
zizi21Asked:
Who is Participating?
 
sciuriwareCommented:
How about:

   JTextArea a = new JTextArea(30, 80);

    for(int i=0;i<3;i++)
    {
          for(int j=0;j<2;j++)
          {
          a.append(obj[i][j].getName() + "   "); // 3 spaces trailing
          a.append(obj[i][j].getSchool() + '\n');  // Newline
    }

If 'a' grows too big, put it in a JScrollPane.

;JOOP!
0
 
CEHJCommented:
You need to create a new JLabel for each one and call panel.add on it. If you need to keep the references to each label, you need to use an array of labels too
0
 
CEHJCommented:
Something like

// Outside loop
JLabel[][] labels = new JLabel[i][j];
// The following inside loop
labels[i][j] = new JLabel(obj[i][j].getName());
panel.add(labels[i][j]);
0
 
sciuriwareCommented:
:))
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.