Alan Blass wrote:Hi! How do I check if a component exists in a container and replace it if it exists.
If you have a requirement to know whether a container actually contains a particular component, then you should write your application to keep track of that information. For example, when you add the component to the container, set some boolean flag to true. And when you remove it from the container, set that flag to false.
Rob Prime wrote:When called during runtime, remember to call revalidate() and repaint() on the JPanel. Components do not trigger any updates to be repainted when their hierarchical structure is modified.
I was going to suggest that when I read the OP, but found that GroupLayout#replace takes care of it.
subject: How to check if a component exists in Swing?