Qustion about dynamic content

If I do something like the following:

frame.setVisible(true);

frame.add(new JLabel("A Label"));

The label does not appear. (it does if the add is before the setVisible.) Why? This seems to indicate that the only way to get dynamic content in any container is to use paint and paintComponent. Is that true?

[330 byte] By [Will2Playa] at [2007-10-3 9:40:44]
# 1

When you add a component to a container when the GUI is visible you need to use:

container.revalidate();

This will invoke the layout manager so the components can be layed out correctly.

> This seems to indicate that the only way to get dynamic content in any

> container is to use paint and paintComponent. Is that true?

No and you should never override paint(). Custom painting is done in the paintComponent() method.

camickra at 2007-7-15 4:56:45 > top of Java-index,Desktop,Core GUI APIs...