JavaFx SceneBuilder 2.0 不解析自定义控件

标签 java intellij-idea javafx scenebuilder

我有一个在我的应用程序中呈现的自定义 JavaFx 控件。但是,我无法让 SceneBuilder 理解它。

我有 CustomTextField.java/CustomTextField.fxml。 CustomTextField 继承自 UserControl,定义为 here ,但我创建的任何自定义控件都会出现场景生成器问题。

首先,我必须将导入语句更改为通配符。来自

<import sample.CustomTextField>

<import sample.*>

否则,scenebuilder 会抛出异常/显示堆栈跟踪,表明无法找到源文件。我不知道为什么这是必要的,但它似乎有效,所以我继续前进。

我听说您也在 fxml 文件中指定了一个 scenebuilder-classpath-element。所以,我尝试了所有我能想到的组合:

<?scenebuilder-classpath-element ../../bin?>
<?scenebuilder-classpath-element ../../out?>
<?scenebuilder-classpath-element ../../../out?>
<?scenebuilder-classpath-element ./?>
<?scenebuilder-classpath-element ../../../../../target/classes?>

我的问题是自定义控件未在 Scene Builder 中呈现。在层次树中选择它,它表示“选择包含未解析的引用”。如果我不能拖放自定义控件,那是可以接受的。但是,我真的很想在 Scene Builder 中渲染它并布置其他内容。

我正在使用 IntelliJ IDEA 14 和 Scene Builder 2.0

示例.fxml:

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

<?import javafx.scene.control.*?>
<?import javafx.scene.layout.*?>
<?import sample.*?>

<?scenebuilder-classpath-element ../../bin?>
<?scenebuilder-classpath-element ../../out?>
<?scenebuilder-classpath-element ../../../out?>
<?scenebuilder-classpath-element ./?>
<?scenebuilder-classpath-element ../../../../../target/classes?>

<Pane maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" prefHeight="400.0" prefWidth="600.0" xmlns="http://javafx.com/javafx/8" xmlns:fx="http://javafx.com/fxml/1">
   <children>
      <Button fx:id="topButton" layoutY="2.0" mnemonicParsing="false" text="Button Top" />
       <CustomTextField fx:id="myCustomTextField" layoutX="1.0" layoutY="40.0" />
       <Button layoutX="1.0" layoutY="125.0" mnemonicParsing="false" text="Button Bot" />
   </children>
</Pane>

project structure enter image description here

最佳答案

我能够加载自定义类。我们通过使用自定义类构建 .jar 来实现它,然后在 SceneBuilder 中,转到搜索库旁边的设置图标并导入自定义库。然后找到你的.jar。也许您可以对 .class 文件做同样的事情?

这是 .fxml 中的导入语句:

<?import com.rlsciences.autoredact.view.ItemsTableView?>

这是我在 .fxml 中使用它的地方:

<ItemsTableView id="searchResultsTableView" fx:id="searchResultsTableView" fixedCellSize="20.0" styleClass="compact-table" VBox.vgrow="ALWAYS">

这是类定义:

package com.rlsciences.autoredact.view;
public class ItemsTableView<S> extends TableView<S>

关于JavaFx SceneBuilder 2.0 不解析自定义控件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32526902/

相关文章:

Java GUI 显示为空白

android - 最新的 IntelliJ IDEA 12 预览版构建了 ActionBarSherlock 的中断渲染

JavaFX - TableColumn 图形高于其他行

java - CAS 4.2.2 的多个属性文件

java - 具有不同上下文根的单个耳朵中的多个 war 文件

java - MongoDB,Java,按第一个数组条目排序

java - 找不到更新日志 changelog.groovy

java - 在 IntelliJ IDEA 中突出显示异常抛出者

JavaFX ScrollPane的水平滚动条隐藏内容

java - TableView:如何在角菜单中启用加速器?