label wont show up unless window resized

hi i have a strange problem, here s the code

/**

* Displays the specified contact

*/

publicvoid displayContact(Contact c)

{

final Contact contact = c;// contact is another class

contactDisplay.removeAll();//contactDisplay is a panel contained in a splitpane

_value.setText(contact.getSurname());//_value is a jlabel

contactDisplay.add(_value);

//System.out.println(contact.getSurname() + contact.getForename());

contactDisplay.repaint();

}

publicvoid valueChanged(javax.swing.event.ListSelectionEvent e){

Contact c = (Contact)contactlist.getSelectedValue();

displayContact(c);

}

basically, a splitpane containts 2 panels, one for contact list and one for displaycontact. once a contact is cliked details should be displayed on the displaycontact panel. however, this does not work unless i readjust the split bar. i.e., if i click on contact A, or B, or C, nothing shows up on the displaycontact panel. but if then i adjust the split bar, or just clikc on it, everything shows up! and program then runs well! ive totally no clue whats goin on here..... help please!

[1604 byte] By [zqzuka] at [2007-10-2 5:03:36]
# 1

hi, sorry looks like ive sorted the problem, i know whats causing the prob but still dont know why...... the code should goes this rather than above:

/**

* Displays the specified contact

*/

public void displayContact(Contact c)

{

final Contact contact = c;

contactDisplay.removeAll();

contactDisplay.setLayout(new GridLayout(15,2));

contactDisplay.add(_surname);// _surname is a label with text "surname"

//// LINE A

contactDisplay.add(_snvalue);//_value is a label contains value of surname

_snvalue.setText(contact.getSurname());///// LINE B

//System.out.println(contact.getSurname() + contact.getForename());

contactDisplay.repaint();

}

the problem is, if line b is moved to a, the problem happens exactly as described in above trhead. if moved down to line b, then problem solved.... why is that? any hint please? thanks!

zqzuka at 2007-7-16 1:07:12 > top of Java-index,Desktop,Core GUI APIs...
# 2
I don't know what that fixes the problem.Normally, after you add or remove components from a container, you need to use:container.revaliate();
camickra at 2007-7-16 1:07:12 > top of Java-index,Desktop,Core GUI APIs...
# 3
thanks, thats very useful and i think is indeed the correct solution!
zqzuka at 2007-7-16 1:07:12 > top of Java-index,Desktop,Core GUI APIs...