Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
Comment: add a few phrases for clarity

In order to have different component hierarchies in your markup and
Java, you need an indirection; make two Panels for your component.
Then conditionally add one panel or the other to the enclosing component.

The following example displays either an external link or some text.

...

Another approach is to add all components you might want to display, and make all invisible (using Component.setVisible()) but the one you want to show. This usually takes less code, but it is also much less flexible and not suited for cases where you have a lot of possible components or creating the components is expensive.

...