Skip to Main Content

Problem loading a custom control jar into scene builder

3193630Mar 8 2016 — edited Mar 10 2016

Hi, I am new to java Fx and want to create a custom control of text field  for unit conversion though I am able to make it operational but there is problem in loading the jar when I want to use in other application

Here is my ConvertTextField.java

public class ConvertTextField extends TextField{

  ConvertTextFieldSkin convertTextFieldSkin = new ConvertTextFieldSkin(this);

     public ConvertTextField() {

         this("");

     }

     public ConvertTextField(final String TEXT) {

         super(TEXT);

         final ConvertTextField convertTextField = this;

         getStylesheets().add(getClass().getResource("application.css").toExternalForm());

         }

}

Here is ConvertTextFieldSkin.java

public class ConvertTextFieldSkin extends SkinBase<ConvertTextField>{

  private static SimpleStringProperty NewUnit = new SimpleStringProperty();

  private static SimpleDoubleProperty Number = new SimpleDoubleProperty();

  ComboBox<String> ComboBox = new ComboBox<String>();

  public ConvertTextFieldSkin(final ConvertTextField convertTextField) {

  super(convertTextField);

  ComboBox.getItems().addAll(

                "yrds",

                "cbl",

                "mtr",

                "Nm"

               );

     ComboBox.setValue("yrds");

     ComboBox.setPrefWidth(70);

     ComboBox.setMaxHeight(25);

  getChildren().add(ComboBox);

  convertTextField.setOnAction(new EventHandler<ActionEvent>()

        {     

        @Override

  public void handle(ActionEvent event) {

  System.out.println("Text :: "+convertTextField.getText().toString()+" unit ::"+NewUnit.getValue());

     double InNumber=0;

  InNumber= Double.valueOf(convertTextField.getText().toString());

  Number.setValue(InNumber);

  }       });   

  ComboBox.getSelectionModel().selectedItemProperty().addListener(new ChangeListener<String>() {

      @Override

      public void changed(ObservableValue<? extends String> observable,String 

    oldValue,String newValue)

    {

       System.out.println("   New Unit  ::: "+ newValue + "  Old Unit :: "+ oldValue+"  Value :: "+Number.getValue()+"  New :: "+NewUnit.getValue());

     NewUnit.setValue(newValue); 

   System.out.println("Output"+ConvertUnit(oldValue, newValue,Number.getValue() )) ; 

  convertTextField.setText(Double.toString(ConvertUnit(oldValue, newValue,Number.getValue() ))); 

    }   

  });

  }  public double ConvertUnit(String OldUnit, String NewUnit, double input)

  {

  double output = 0;

  //Some operations

  return output;

  }  

}

Here is ConvertTextFieldDemo.java

public class ConvertTextFieldDemo extends Application {

  @Override public void start(Stage stage) {

        ConvertTextField TextBox = new ConvertTextField();

        StackPane pane = new StackPane();

        pane.getChildren().add(TextBox);

        Scene scene = new Scene(pane, 400, 70);

        stage.setScene(scene);

        stage.setTitle("JavaFX ");

        stage.show();

}

  public static void main(String[] args) {

         Application.launch(args);

     }

}

errors (jar analysis report)

Not a Node: application/ConvertTextFieldDemo.class

Exception for: application/ConvertTextFieldSkin.class

javafx.fxml.LoadException:

unknown path:2

  at javafx.fxml.FXMLLoader.constructLoadException(FXMLLoader.java:2617)

  at javafx.fxml.FXMLLoader.access$700(FXMLLoader.java:104)

  at javafx.fxml.FXMLLoader$InstanceDeclarationElement.constructValue(FXMLLoader.java:1012)

  at javafx.fxml.FXMLLoader$ValueElement.processStartElement(FXMLLoader.java:740)

  at javafx.fxml.FXMLLoader.processStartElement(FXMLLoader.java:2723)

  at javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:2527)

  at javafx.fxml.FXMLLoader.load(FXMLLoader.java:2425)

  at com.oracle.javafx.scenebuilder.kit.library.util.JarExplorer.instantiateWithFXMLLoader(JarExplorer.java:105)

  at com.oracle.javafx.scenebuilder.kit.library.util.JarExplorer.exploreEntry(JarExplorer.java:146)

  at com.oracle.javafx.scenebuilder.kit.library.util.JarExplorer.explore(JarExplorer.java:65)

  at com.oracle.javafx.scenebuilder.kit.library.user.LibraryFolderWatcher.exploreAndUpdateLibrary(LibraryFolderWatcher.java:298)

  at com.oracle.javafx.scenebuilder.kit.library.user.LibraryFolderWatcher.runDiscovery(LibraryFolderWatcher.java:122)

  at com.oracle.javafx.scenebuilder.kit.library.user.LibraryFolderWatcher.run(LibraryFolderWatcher.java:88)

  at java.lang.Thread.run(Thread.java:744)

Caused by: java.lang.InstantiationException: application.ConvertTextFieldSkin

  at java.lang.Class.newInstance(Class.java:418)

  at sun.reflect.misc.ReflectUtil.newInstance(ReflectUtil.java:51)

  at javafx.fxml.FXMLLoader$InstanceDeclarationElement.constructValue(FXMLLoader.java:1010)

  ... 11 more

Caused by: java.lang.NoSuchMethodException: application.ConvertTextFieldSkin.<init>()

  at java.lang.Class.getConstructor0(Class.java:2971)

  at java.lang.Class.newInstance(Class.java:403)

  ... 13 more

Comments
Post Details
Added on Mar 8 2016
3 comments
973 views