Custom controls – JavaFX custom controls (textfield) do not work

I tried to customize controls with JavaFX and scenebuilder 1.1

I have this Code:

FXML

<?import libreria.javaFX.componentes.componenteTextField.*?>

<AnchorPane id="AnchorPane" maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" prefHeight="400.0" prefWidth="600.0" xmlns:fx="http://javafx.com/fxml">
  <children>
    <CustomComponent fx:id="pastaTxt" layoutX="69.0" layoutY="87.0" prefWidth="200.0" />
  </children>
</AnchorPane>

CustomComponent. java

package libreria.javaFX.componentes.componenteTextField;

import javafx.scene.control.TextField;

public class CustomComponent extends TextField {

public CustomComponent() {
    super();
    // TODO Auto-generated constructor stub
}

public CustomComponent(String arg0) {
    super(arg0);
    // TODO Auto-generated constructor stub
}

}

When I try to open it from scenebuilder, it tells me:

And it gives me the opportunity to specify classpath (without solving the problem)

I try to put the class on the import statement, like this:

<?import libreria.javaFX.componentes.componenteTextField.CustomComponent?>

But it will give a classnotfoundexception

What do you think? Why did this happen?

More information

I just finished a new project:

The code is as follows:

CustomControl. fxml

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

<?import custom.CustomControl?>
<?import java.lang.*?>
<?import java.util.*?>
<?import javafx.scene.control.*?>
<?import javafx.scene.layout.*?>
<?import javafx.scene.paint.*?>
<?scenebuilder-classpath-element ../../bin/custom?>

<AnchorPane id="AnchorPane" maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" prefHeight="400.0" prefWidth="600.0" xmlns:fx="http://javafx.com/fxml">
  <children>
    <CustomControl layoutX="51.0" layoutY="100.0" prefWidth="200.0" />
  </children>
</AnchorPane>

CustomControl. java

package custom;

import javafx.scene.control.TextField;

public class CustomControl extends TextField {

    public CustomControl() {
        super();
    }

public CustomControl(String arg0) {
    super(arg0);

    }
}

I have the same question I specified the classpath with the dialog box. Everything seems to me, but I also made the same error when I opened scenebuilder

Recent information

Trying to approach the solution, we tried this project under eclipse As a result, the eclipse display window is OK, but scenebuilder continues with these errors I hope this clue will help

If someone has completed this custom control definition under scene builder, please tell us and give us an example, which is very helpful for our project

Solution

This is because the correct class path is not specified, which allows the Java runtime scenario builder to load the control class

If you are running eclipse and your class has the namespace custom Mycontrol then specifies the bin directory instead of the custom directory In the Maven project, you need to specify the target / class directory

I saw an example in my own project: https://bitbucket.org/atill/estimate/src/22390a2ca034b55f1916e46435b714e5c489b90e/src/main/resources/projmon/gui/workTree.fxml?at=master

The relative file path is usually created by the scene builder, so the moved file will destroy the classpath and you will need to redefine it

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>