Update:
This template is made for JavaFX 1.2! For 1.3 use the template posted here instead.

Here is a small template that helps you to create your own custom control without any problem:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
public class MyControl extends Control {
    override function create(): Node {
        if ( skin == null ){
          skin = MySkin{};
        }
        super.create();
    }
}


public class MySkin extends Skin {
  def myBehavior = bind behavior as MyOwnBehaviour;
  def myControl = bind control as MyOwnControl;

  init {
    node =  Rectangle {
      width: bind control.width
      height: bind control.height
    }
    behavior = MyOwnBehaviour{};
  }

  override function getPrefWidth( number ) {
    //return your pref width - hard coded values are ok for most cases
  }

  override function getPrefHeight( number ) {
    //return your pref height - hard coded values are ok for most cases
  }

/*
//It is not absolutly necessary to override those methods, but strongly recommended.
  override function getMinWidth() {
  }

  override function getMinHeight() {
  }

  override function getMaxWidth() {
  }

  override function getMaxHeight() {
  }
*/


  override function contains( localX: Number, localY: Number ): Boolean {
    node.contains( localX, localY );
  }

  override function intersects( localX: Number, localY: Number, localWidth: Number, localHeight: Number ): Boolean {
    node.intersects( localX, localY, localWidth, localHeight );
  }
}

public class MyOwnBehaviour extends Behavior {
  def myControl = bind skin.control as MyOwnControl;
}