I am trying to create a custom control in JavaFx. The main aim is to create a node that acts as a button. It is simply a Label that would be styled with css to look like a button. I have created a class MyControl that extends the control class like so:
public class MyControl extends Control { @Override protected String getUserAgentStylesheet() { return MyControl.class.getResource("myControl.css").toExternalForm(); } public MyControl() { getStyleClass().add("new-control"); } public MyControl(String item) { getStyleClass().add("new-control"); } } } For the SkinBase class MyControlSkin I have:
public class MyControlSkin extends SkinBase<MyControlSkin> { public MyControlSkin(MyControlSkin control) { super(control); Label label = new Label("Some text here"); getChildren.add(label); } } In the myControl.css file i simply have:
.tree-node-view { -fx-skin: "treeviewsample.TreeViewSkin"; } .label { -fx-text-fill: -fx-text-background-color; } I have created the css for this but the problem is that I don't see the label displayed on the scene:
MyControl control = new MyControl(); but no Label displays on the screen. Please help me I am new to this so ask me for more information if in case my question does not make sense.
I am using javaFx 2.2