What to use: CustomComponent or Panel?

After testing around a little with Vaadin a discussion arose about which is the recommendable unit-of-work in Vaadin, providing maximum of flexibility and sophisticated resize- and layout-behaviour:

  • Panel
  • CustomComponent
  • VerticalLayout, HorizontalLayout, GridLayout

With unit-of-work I mean the “building blocks” of the UI. Containers that might be moved around or reused in course of time.

As an AWT programmer I would recommend java.awt.Panel
As a Swing programer I would recommend javax.swing.JPanel.
As a Vaadin programmer … ?

I go with the layout that I want to use: VerticalLayout, HorizontalLayout, GridLayout, CssLayout etc. It is basically the same as going with a Panel, but faster as the extra Panel is not added around your layout which brings down performance. Nowadays i never go with CustomComponent, and only with Panel if the block of UI requires scrolling of it’s own.

One advantage that a CustomComponent has over a layout: better abstraction. It does not expose layout operations such as addComponent() to the users of the building block.

Otherwise, using a suitable layout (and not relying on the exact layout in the code using the component) is often an efficient way.

So I understand:
take a Panel if the content might need scrolling,
else choose your best practice:
separate layout from containers - take CustomComponent,
or integrate layout into container - take one of XxxLayout.

Thanks!