Possible Duplicate:
How to dynamically add JLabels to JPanel?
I have a created a panel and using a gridlayout for it.
public pnlFriends() { initComponents(); this.setLayout(new GridLayout(10,1)); // showFriends(); } private void formComponentShown(java.awt.event.ComponentEvent evt) { showFriends(); System.out.print("comp"); } private void showFriends() { //Integer id = NewMain.network.getEdges().get(Main.uuid).getDegree(); for(int i = 0;i < 10 ;i++) { String name = "as"; String occupation ="adf"; String place = "asdf"; Integer connections = 5; this.add(displayMiniProfile(name,occupation,place,connections)); } }
where the displayMiniProfile
return a JPanel.
Now when I have this function called in the constructor of the parent JPanel, it works and I can add MiniProfile JPanel.
But when I am calling this function in the response of componentshown
event it doesn't show anything.
WHY ?
And how can I achieve the same ?