SceneBuilder-添加依赖第三方组件的自定义组件 [英] SceneBuilder - Add custom component which relies on third party components

查看:352
本文介绍了SceneBuilder-添加依赖第三方组件的自定义组件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以这篇文章:自定义FXML组件(带有控制器)未出现在SceneBuilder的导入jar"中对话框

它说您不能导入依赖第三方组件的自定义组件.但是我不敢相信这(这很愚蠢)……我现在正努力根据图书馆 JFoenix 中的组件创建自定义组件.

It says you cant import custom components which rely on third party components. But I cant believe this (this would be stupid) ... Im struggling now to create a custom component based on components from the Library JFoenix.

所以我有这个fxml和控制器:

So i have this fxml and controller:

SelectableList.fxml

SelectableList.fxml

<?xml version="1.0" encoding="UTF-8"?>
<?import com.jfoenix.controls.JFXButton?>
<?import com.jfoenix.controls.JFXListView?>
<?import javafx.geometry.Insets?>
<?import javafx.scene.control.Label?>
<?import javafx.scene.layout.AnchorPane?>
<?import javafx.scene.layout.VBox?>
<?import javafx.scene.text.Font?>

<fx:root type="AnchorPane" xmlns="http://javafx.com/javafx/10.0.1" xmlns:fx="http://javafx.com/fxml/1">
   <children>
      <VBox alignment="TOP_CENTER" prefHeight="743.2" prefWidth="400.0" AnchorPane.bottomAnchor="0.0" AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="0.0" AnchorPane.topAnchor="0.0">
         <children>
            <Label fx:id="titleLabel" text="Title" textFill="#000000de">
               <font>
                  <Font name="Roboto Medium" size="36.0" />
               </font>
               <VBox.margin>
                  <Insets bottom="40.0" top="40.0" />
               </VBox.margin>
            </Label>
            <JFXListView fx:id="itemList" prefHeight="660.0" prefWidth="400.0" />
            <JFXButton fx:id="addButton" focusTraversable="false" onAction="#addElement" prefHeight="50.0" prefWidth="500.0" styleClass="addbutton" stylesheets="@application.css" text="+" textFill="#21ce12ad">
               <font>
                  <Font name="Roboto" size="33.0" />
               </font>
            </JFXButton>
         </children>
      </VBox>
   </children>
</fx:root>

SelectableList.java

SelectableList.java

package de.goehring.components;

import com.jfoenix.controls.JFXButton;
import com.jfoenix.controls.JFXListView;
import javafx.fxml.FXML;
import javafx.fxml.FXMLLoader;
import javafx.scene.control.Label;
import javafx.scene.layout.AnchorPane;

import java.io.IOException;

public class SelectableList<T> extends AnchorPane  {

    @FXML
    private Label titleLabel;

    @FXML
    private JFXListView<T> itemList;

    @FXML
    private JFXButton addButton;

    public SelectableList() {
        FXMLLoader fxmlLoader = new FXMLLoader(getClass().getResource("SelectableList.fxml"));
        fxmlLoader.setRoot(this);
        fxmlLoader.setController(this);
        try {
            fxmlLoader.load();
        } catch (IOException exception) {
            throw new RuntimeException(exception);
        }
    }


    @FXML
    void addElement() {

    }

}

我到底在做什么错.当我导入为jar时,我的SceneBuilder无法识别此组件.

Exactly what am I doing wrong. My SceneBuilder does not recognize this component when being imported as jar.

推荐答案

@slaw发布的相关问题解决了我的问题.

The related question posted by @slaw solved my issue.

要研究它: SceneBuilder嵌套的自定义节点

因此,基本上,如果您对本主题感到困惑,请克隆SceneBuilder并通过在工具包项目下检查类JarExplorer开始调试它.

So basically , if you are struck with this topic, clone SceneBuilder and start debugging it by checking under the kit project the class JarExplorer.

通过x.printStacktrace()添加stacktrace输出时,您会看到未加载项目的原因.

When adding a stacktrace output via x.printStacktrace() you see the reason why your project hasnt been loaded.

因此,在我的情况下,正如所链接的文章所提到的:您需要设置正确的类加载器.(还有一个斜杠.请诅咒您的Java资源.)

So in my case, it was as mentioned by the post linked : you need to set the correct classloader. (and a missing slash. Curse you java resources.)

这就是我的构造函数现在的样子:

So this is what my constructor looks now:

    FXMLLoader fxmlLoader = new FXMLLoader(getClass().getResource("/SelectableList.fxml"));
    fxmlLoader.setRoot(this);
    fxmlLoader.setController(this);
    fxmlLoader.setClassLoader(getClass().getClassLoader());
    try {
        fxmlLoader.load();
    } catch (IOException exception) {
        throw new RuntimeException(exception);
    }

然后,它就很好了.

如果有人在启动SceneBuilder项目时遇到问题:

If someone has issues launching the scenebuilder project:

使用IntelliJ.您可以单击build.gradle并启动运行"任务.由于Java 11需要在命令行中加载模块,因此可以使用此方法.否则,您会收到一条错误消息,提示您缺少"JavaFX组件".

Use IntelliJ. You can click on the build.gradle and start the "run" task. Since java 11 requires modules loaded in the command line you can use this method. Otherwise you get an error which tells you "JavaFX Components" are missing.

希望这会有所帮助.

这篇关于SceneBuilder-添加依赖第三方组件的自定义组件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆