Is it possible to import a JAR containing a custom JavaFX control into Scene Builder?

不问归期 提交于 2019-12-01 06:19:21

You do not need .jar file to do that. You can simply create new FXML file with that what you need ex. combo box. Create class file with extending combo box, controller and add controller in FXML file (in scene builder).

Find "Import from JAR/FXML file" in combo box near to left search box in scene builder and then select the file. Now you have new title pane in left accordion with name Custom. There you can find your components.

@edit There are files.

MyGridPane.fxml

<?xml version="1.0" encoding="UTF-8"?>

<?import java.lang.*?>
<?import javafx.scene.layout.*?>

<fx:root type="javafx.scene.layout.GridPane" maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" prefHeight="400.0" prefWidth="600.0"  xmlns:fx="http://javafx.com/fxml/1" xmlns="http://javafx.com/javafx/8" fx:controller="MyGridPane.MyGridPaneController">
  <columnConstraints>
    <ColumnConstraints hgrow="SOMETIMES" minWidth="10.0" prefWidth="100.0" />
    <ColumnConstraints hgrow="SOMETIMES" minWidth="10.0" prefWidth="100.0" />
  </columnConstraints>
  <rowConstraints>
    <RowConstraints minHeight="10.0" prefHeight="30.0" vgrow="SOMETIMES" />
    <RowConstraints minHeight="10.0" prefHeight="30.0" vgrow="SOMETIMES" />
    <RowConstraints minHeight="10.0" prefHeight="30.0" vgrow="SOMETIMES" />
  </rowConstraints>
</fx:root>

MyGridPane.java

package MyGridPane;

import javafx.fxml.FXMLLoader;
import java.io.IOException;

/**
 * Created by Marcin on 2014-09-01.
 */
public class MyGridPane {
    MyGridPane(){
        FXMLLoader fxmlLoader = new FXMLLoader(getClass().getResource("MyGridPane.fxml"));
        fxmlLoader.setRoot(this); fxmlLoader.setController(this);
        try {
            fxmlLoader.load();
        } catch (IOException exception) {
            throw new RuntimeException(exception);
        }
    }
}

MyGridPaneController.java

package MyGridPane;

import javafx.fxml.Initializable;

import java.net.URL;
import java.util.ResourceBundle;

/**
 * Created by Marcin on 2014-09-01.
 */
public class MyGridPaneController implements Initializable{
    @Override
    public void initialize(URL location, ResourceBundle resources) {

    }
}

Next step is add to Scene Builder

and you can add this component.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!