fxml - Using custom javafx label doesn't work -


ok i've created own customer label, example it's extremely basic. did extend javafx label in custom class called mylabel. i'm using fxml create gui. when can't seem instantiate custom class error.

"can not set net.blacksquirreldevs.tests.mylabel field net.blacksquirreldevs.tests.samplelabelcontroller.samplelabel javafx.scene.control.label" 

here code everything

main.java

package net.blacksquirreldevs.tests;  import javafx.application.application; import javafx.fxml.fxmlloader; import javafx.scene.scene; import javafx.scene.layout.anchorpane; import javafx.stage.stage;  public class main extends application {  @override public void start(stage primarystage) throws exception {     primarystage.settitle("samplelabel");     anchorpane anchorpane = (anchorpane)     fxmlloader.load(getclass().getresource("samplelabel.fxml"));      primarystage.setscene(new scene(anchorpane));     primarystage.show(); }  public static void main(string... args) {     launch(args); } } 

mylabel.java

package net.blacksquirreldevs.tests;  import javafx.scene.control.label;   public class mylabel extends label {  public mylabel(string text) {     super();     settext(text); } } 

samplelabelcontroller.java

package net.blacksquirreldevs.tests;  import javafx.fxml.fxml;  import java.net.url; import java.util.resourcebundle;   public class samplelabelcontroller {  @fxml private resourcebundle resources; @fxml private url location; @fxml private mylabel samplelabel = new mylabel("hello world!");   @fxml void initialize() {     assert samplelabel != null : "fx:id=\"samplelabel\" not injected: check fxml file 'samplelabel.fxml'.";   }  } 

and fxml file samplelabel.fxml

<?xml version="1.0" encoding="utf-8"?>  <?import java.lang.*?> <?import java.util.*?> <?import javafx.scene.control.*?> <?import javafx.scene.layout.*?> <?import javafx.scene.paint.*?> <?import javafx.scene.text.*?>  <anchorpane id="anchorpane" maxheight="-infinity" maxwidth="-infinity" minheight="-infinity" minwidth="-infinity" prefheight="400.0" prefwidth="600.0" xmlns:fx="http://javafx.com/fxml" fx:controller="net.blacksquirreldevs.tests.samplelabelcontroller"> <children> <label fx:id="samplelabel" layoutx="153.0" layouty="171.0" text="sample text">   <font>     <font name="arial bold" size="50.0" />   </font> </label> </children> </anchorpane> 

so want know why can' declare, in samplelabelcontroller class, samplelabel mylabel?

hopefully i've explained enough, if not let me know , i'll try go bit more in detail.

you using <label ... in fxml instead of <mylabel

beside mylabel has none default constructor , in case need provide builder named mylabelbuilder fxmlloader can create instance of mylabel


Comments

Popular posts from this blog

Perl - how to grep a block of text from a file -

delphi - How to remove all the grips on a coolbar if I have several coolbands? -

javascript - Animating array of divs; only the final element is modified -