简体   繁体   English

JavaFx SceneBuilder 2.0无法解析自定义控件

[英]JavaFx SceneBuilder 2.0 not resolving custom controls

I have a custom JavaFx control that renders in my application. 我有一个自定义JavaFx控件,可在我的应用程序中呈现。 But, I can't get SceneBuilder to understand it. 但是,我无法让SceneBuilder理解它。

I have CustomTextField.java / CustomTextField.fxml. 我有CustomTextField.java / CustomTextField.fxml。 CustomTextField inherits from UserControl, as defined here , but my scene builder problem happens with any custom control that I create. 从用户控件CustomTextField继承,定义在这里 ,但是我的场景建设者问题,任何自定义的控制,我创建情况。

First, I had to change my import statement to be a wildcard. 首先,我必须将import语句更改为通配符。 From

<import sample.CustomTextField>

to

<import sample.*>

otherwise, scenebuilder threw an exception / showed a stacktrace indicating that the source file couldn't be found. 否则,scenebuilder抛出异常/显示堆栈跟踪信息,表明找不到源文件。 I have no idea why this was necessary, but it seemed to work, so I kept moving. 我不知道为什么这样做是必要的,但是它似乎行得通,所以我不断前进。

I had read that you to specify a scenebuilder-classpath-element in the fxml file as well. 我读过您在fxml文件中也指定一个scenebuilder-classpath-element。 So, i tried every combination I could think of: 因此,我尝试了所有我能想到的组合:

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

My issue is that the custom control does not render in Scene Builder. 我的问题是自定义控件无法在Scene Builder中呈现。 SElecting it in the hiearchy tree, it indicates "Selection contains unresolved reference". 在层次树中选择它,它指示“选择包含未解析的参考”。 If I can't drag/drop the custom control around, that's acceptable. 如果我不能拖放自定义控件,那是可以接受的。 However, I really want to render this in Scene Builder and lay out other stuff. 但是,我真的很想在Scene Builder中渲染它并布置其他内容。

I am using IntelliJ IDEA 14, and Scene Builder 2.0 我正在使用IntelliJ IDEA 14和Scene Builder 2.0

sample.fxml: sample.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>

项目结构 在此处输入图片说明

I'm able to load custom classes. 我能够加载自定义类。 We got it to work by building a .jar with the custom classes, then in SceneBuilder, go to the settings icon next to searching the library and import custom library. 我们通过使用自定义类构建.jar使其工作,然后在SceneBuilder中转到搜索库旁边的设置图标并导入自定义库。 Then find your .jar. 然后找到您的.jar。 Maybe you could do the same thing with .class files? 也许您可以对.class文件执行相同的操作?

Here's the import statement in the .fxml: 这是.fxml中的import语句:

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

Here's where I'm using it in the .fxml: 这是我在.fxml中使用它的位置:

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

Here's the class definition: 这是类的定义:

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM