How to add small panels to a bigger panel Dynamically

I have a frame which has scroll A and scroll pame B,

scrollpane A has a panel C ( the bigger panel mentioned in the title)

Now I have to add other smaller panels to the to panel C when the user clicks on a JButton A .

i have another JButton B , when user clicks this button the visibility of Scrollpane A and ScrollPane B is alternated.

so My problem is here . if the user were to click Jbutton A four times

4 smaller panels should be added and displayed on panle C but it never gets diplayed i tried repaint () that didnt work. for now what i have done is add two lines o setVsible () code which makes panel C blink, to the jbutton a listener . This is one solution i came up with . I am looking for another

any help is greatly appreciated

thanks in advaced

[813 byte] By [dupemastera] at [2007-10-3 4:28:20]
# 1

You need to validate the panel after modifying its children.

private JButton createAdderButton(final JComponent c)

{

final JButton b = new JButton();

b.addActionListener(new ActionListener()

{

public void actionPerformed(ActionEvent e)

{

c.add(new JLabel("Added"));

c.revalidate();

}

});

return b;

}

itchyscratchya at 2007-7-14 22:31:18 > top of Java-index,Desktop,Core GUI APIs...
# 2
revalidate() was the trick thanks.
dupemastera at 2007-7-14 22:31:18 > top of Java-index,Desktop,Core GUI APIs...