Jump to: navigation, search

Albireo Documentation

Revision as of 15:35, 2 April 2008 by Haible.ilog.fr (Talk | contribs) (First doc)

(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

Getting Started

How do you create an SWT control that encapsulates a Swing component? If you use SWT_AWT by hand, you have to deal with too many details. With Albireo, you instantiate one class, implementing abstract methods, and that's it.

The simplest example is this:

Control c =
  new SwingControl(parent, SWT.NONE) {
    protected JComponent createSwingComponent() {
      return new JLabel("hi, i'm swinging");
    public Composite getLayoutAncestor() {
      return parent;

SwingControl is the class that does it all.

Its constructor takes two arguments, like most SWT components do: The parent control, to which the new control is added as child when it is created, and a set of ORed flags. In the flags, you should not pass SWT.EMBEDDED; just pass the flags that are relevant to you.

You need to implement at least two methods: createSwingComponent and getLayoutAncestor.

createSwingComponent is the method which creates the Swing component. You don't pass a ready-made Swing component as a constructor argument; instead you let it create here. The IlvSwingControl class takes care to call this creation method in the right thread (the AWT event thread) and to attach it in the right place of the control/component hierarchy.

getLayoutAncestor is the method with which you designate which control should be layout()ed when the preferred size of the Swing component changes. Usually it us the parent argument that you passed as first constructor argument. But it can also be the parent's parent.

Customizing ...