Skip to main content

Notice: This Wiki is now read only and edits are no longer possible. Please see: for the plan.

Jump to: navigation, search


Revision as of 11:32, 18 November 2013 by Unnamed Poltroon (Talk) ( moved page E4/XWT/FAQ to XWT/FAQ: new standalone project)

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

I want to develop a Custom Widget using XWT, and the Widget have properties. How to do ?

There are two ways to develop reusable Custom Widgets:

1. In Java

You develop your widget in Java as usual. And this widget can be used directly in XWT using a customized name space: for example we have a
class DecoratedText, a Text with a decoration to indicate the input is mandadory

package ext.custom;
public class DecoratedText extends Composite {
   private Image decorator;
   private Text text;

   private Display display; 

   public DecoratedText(Composite parent, int style) {
     text = new Text(parent, SWT.BORDER);
enum Display {
  None, Always, Error, ToolTip;

You can use it in your XWT as following:

  <Composite xmlns:c="clr-namespace:ext.custom">
     <c:DecoratedText text="name" decorator="<path>" display="Always"/>

Here you have created a prefix for a namespace corresponding to you java package, and then you can use it in your code with class java classes in
the package. The model should respect the Java Bean specification, XWT will reflect your classe and map the XML to this class automatically. If
your class doesn't respect this standard, you need to create a Metaclass and register it in XWT to let XWT knows.

You can also choice to use the default namespace, to do so, you need to register your class:


This call makes your class in part of standard widget. You can use as simply like

     <DecoratedText text="name" decorator="<path>" display="Always"/>

This is the solution to use if you want to override all existing SWT standard widgets.

2. In XWT

You can create your custom widget in XWT, it consists of two files: Java class for event handling and XWT resource.

package ext.custom;
public class DecoratedText {
   private Display display;
   // event handling methods


  <Composite x:Class="ext.custom.DecoratedText">

This component is used in the same way in XWT as Widget in Java.

I recommend to use XWT solution since it allow to change the appearance dynamically, event in runtime.

Back to the top