我正在尝试使用JavaFX和SceneBuilder 1.1创建自定义控件。
我有以下代码:
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
}
当我尝试从SceneBuilder打开它时,它告诉我:
缺失的类型为:[CustomComponent]
并且它给我指定类路径的机会(但这也无法解决问题)。
我也尝试在导入语句中放置类,就像这样:
<?import libreria.javaFX.componentes.componenteTextField.CustomComponent?>
但是它会抛出一个 ClassNotFoundException
异常。
有任何想法为什么会发生这种情况吗?
更多信息
我做了一个新项目,只有这些类:
代码如下:
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);
}
}
我仍然有同样的问题。我用对话框指定了类路径,一切似乎都没问题,但是打开SceneBuilder时仍然出现相同的错误。
最新信息
为了接近解决方案,我们尝试在Eclipse下运行此项目。结果是Eclipse可以正常显示窗口,但是SceneBuilder仍然存在那些错误。希望这个线索能有所帮助。
如果有人在Scene Builder下完成过这种自定义控件定义,请告诉我们并给我们一个示例,这将对我们的项目非常有帮助。