8

I have a custom JavaFx control that renders in my application. But, I can't get SceneBuilder to understand it.

I have CustomTextField.java / CustomTextField.fxml. CustomTextField inherits from UserControl, as defined here, but my scene builder problem happens with any custom control that I create.

First, I had to change my import statement to be a wildcard. From

<import sample.CustomTextField>

to

<import sample.*>

otherwise, scenebuilder threw an exception / showed a stacktrace indicating that the source file couldn't be found. 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. 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. 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.

I am using IntelliJ IDEA 14, and Scene Builder 2.0

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>

project structure enter image description here

Stealth Rabbi
  • 10,156
  • 22
  • 100
  • 176
  • Did load that fxml file in the builder as given [here](https://rterp.wordpress.com/2014/05/21/adding-custom-javafx-components-to-scene-builder-2-0/) – MalaKa Sep 11 '15 at 15:26
  • So in IntelliJ, I can't import an FXML/Jar like when running the stand alone application. I did try loading it in the stand alone application when viewing sample.fxml (top level fxml file), but it didn't seem to do anything. – Stealth Rabbi Sep 11 '15 at 15:31
  • Also, in that example you linked, it's actually creating a tag for the custom control, it's just automating copy/pate of the control's code. This seems wrong to me... and a maintenance nightmare. – Stealth Rabbi Sep 11 '15 at 15:39
  • I was not aware that you can't do that in IntelliJ. Last time I was running the scenebuilder outside of IntelliJ. There it worked fine when I created a jar file from my custom elements (I did not try the fxml-version). – MalaKa Sep 11 '15 at 15:39

1 Answers1

0

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. Then find your .jar. Maybe you could do the same thing with .class files?

Here's the import statement in the .fxml:

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

Here's where I'm using it in the .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>
Mark Lackey
  • 101
  • 2
  • 3