1

I have created a bunch of custom nodes for my project, by subclassing existing ones.

For example:

package sample;

import javafx.scene.control.Button;

public class MyCustomButton extends Button {
    public MyCustomButton() {    
        System.out.println("This is my custom button...");
    }
}

This is working fine, I create a jar file and I can import it into Scenebuilder.

However if my custom node uses a resource, and I try to import the jar in Scenebuilder, the custom component won't show up in the Import Dialog.

package sample;

import javafx.scene.control.Button;
import javafx.scene.image.Image;

public class MyCustomButton extends Button {
    public MyCustomButton() {
        Image image = new Image("sample/picture.gif");
        System.out.println("This is my custom button...");
    }
}

How can I convince Scenebuilder to import my custom components if they contain resources? The jar file has all the needed resources, and a component working fine in code, but I would like to be able to use it in Scenebuilder as well.

kurgan
  • 83
  • 9
  • Are the resources for the custom component present in the jar file? – ItachiUchiha Feb 15 '15 at 19:38
  • Yes, running `jar tf` shows that resources are present. I can also execute the jar file with `java -jar` which proves that the custom component is working. – kurgan Feb 16 '15 at 22:03
  • Another StackOverflow answer has some information on [importing JAR files into SceneBuilder](http://stackoverflow.com/questions/29444698/how-to-create-an-fxml-file-for-an-already-created-new-component-in-java-than-add). I'm not sure if it will exactly solve your issue (as that imported sample has no additional resources than the Java based control code), but it may help provide you some assistance in working out a resolution. – jewelsea Apr 16 '15 at 20:17

2 Answers2

2

I did for you:)

import javafx.scene.control.Button;
import javafx.scene.image.Image;
import javafx.scene.image.ImageView;

public class MyCustomButton extends Button {
    public MyCustomButton() {
        final ImageView   imageView = new ImageView();

        Image image = new Image(getClass().getClassLoader().getResource("sample/picture.png").toExternalForm());

        imageView.setImage(image);
        this.setGraphic(imageView);
        System.out.println("This is my custom button...");

    }
}
0

Check the analysis report on SB. Click on the settings icon on the right hand side of Library, then select "Custom Library Folder" --> "Show Jar Analysis Report". You can see some useful hints. Maybe this helps you.