[英]How to insert an object of a .jar file into Scene Builder?
I am writing a simulation software for my Masters and it consists on a "Graph container" where you can link nodes to generate equations according to what I link. 我正在为我的大师编写一个仿真软件,它包含一个“图形容器”,您可以在其中链接节点以根据我链接的内容生成方程式。 These equations will, then, enable me to simulate my model.
这些方程将使我能够模拟我的模型。 I am using Java 8 and JavaFX for that, with Scene Builder and FXML.
我为此使用Java 8和JavaFX,以及Scene Builder和FXML。
Searching on the web, I found the Graph-Editor ( https://github.com/tesis-dynaware/graph-editor ), which will help me a lot with what I need. 在网上搜索时,我发现了Graph-Editor( https://github.com/tesis-dynaware/graph-editor ),它将对我的需求有所帮助。 Following the Tutorial on the project's site, I could reproduce it and it is running.
按照项目站点上的教程,我可以复制它并使其运行。 But on my software I do not need to create a new window as the tutorial does to use the graphs - instead, I want to have a TabPane that enables me to create as many models as I need, like a text editor, and if I want I can save it on XML, etc...
但是在我的软件上,我不需要像教程中那样使用图来创建新窗口-而是,我想拥有一个TabPane,使我能够根据需要创建尽可能多的模型,例如文本编辑器,如果需要的话希望我可以将其保存在XML等上...
My problem is: I tried to put the graphs from the tutorial inside the Tab
they do on the tutorial (with the getView
method) and it is not working. 我的问题是:我试图将教程中的图形放在它们在教程上所做的
Tab
(使用getView
方法),但它不起作用。 I tried it in two different ways, which result in an empty Tab
, with no nodes and no error on the console. 我以两种不同的方式进行了尝试,这导致一个空的
Tab
,在控制台上没有节点并且没有错误。
First try 第一次尝试
I tried putting into a Pane and set the GraphEditor
inside the Pane. 我尝试放入窗格中并将
GraphEditor
设置在窗格中。
My java code: 我的Java代码:
private GraphEditor graphEditor = new DefaultGraphEditor();
@FXML
private Pane graphEditorPane;
@FXML
public void initialize(){
graphEditorPane = new Pane(graphEditor.getView());
GModel model = GraphFactory.eINSTANCE.createGModel();
graphEditor.setModel(model);
addNodes(model);
}
My FXML code: 我的FXML代码:
<TabPane tabClosingPolicy="UNAVAILABLE" AnchorPane.bottomAnchor="0.0" AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="0.0" AnchorPane.topAnchor="0.0">
<tabs>
<Tab text="Modelo 1">
<content>
<AnchorPane minHeight="0.0" minWidth="0.0">
<children>
<Pane fx:id="graphEditorPane" prefHeight="571.0" prefWidth="1000.0" AnchorPane.bottomAnchor="0.0" AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="0.0" AnchorPane.topAnchor="0.0" />
</children>
</AnchorPane>
</content>
</Tab>
</tabs>
</TabPane>
Second way 第二种方式
I have seen their demo source code and what I understood was that they created an instance of their GraphEditorContainer
object and then their FXML file has that GraphEditorContainer
, but mine doesn't work that way. 我已经看到了他们的演示源代码,并且我了解到他们创建了
GraphEditorContainer
对象的实例,然后他们的FXML文件具有该GraphEditorContainer
,但是我的方式不起作用。 Maybe I got what they did wrong (I am a beginner in Java and JavaFX). 也许我弄明白了他们做错了什么(我是Java和JavaFX的初学者)。
My java code: 我的Java代码:
private GraphEditor graphEditor = new DefaultGraphEditor();
@FXML
private GraphEditorContainer graphEditorContainer;
@FXML
public void initialize(){
graphEditorContainer = new GraphEditorContainer();
GModel model = GraphFactory.eINSTANCE.createGModel();
graphEditor.setModel(model);
graphEditorContainer.setGraphEditor(graphEditor);
addNodes(model);
}
My FXML code: 我的FXML代码:
<?import de.tesis.dynaware.grapheditor.GraphEditorContainer?>
<TabPane tabClosingPolicy="UNAVAILABLE" AnchorPane.bottomAnchor="0.0" AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="0.0" AnchorPane.topAnchor="0.0">
<tabs>
<Tab text="Modelo 1">
<content>
<AnchorPane minHeight="0.0" minWidth="0.0">
<children>
<GraphEditorContainer fx:id="graphEditorContainer" minWidth="0" minHeight="0" maxWidth="+Infinity" maxHeight="+Infinity"/>
</children>
</AnchorPane>
</content>
</Tab>
</tabs>
</TabPane>
I could put the code that opens the window and draws the nodes in the handleNew
function (code below), but not in the Tab. 我可以将打开窗口并绘制节点的代码放在
handleNew
函数(下面的代码)中,而不是在Tab中。
Stage secondaryStage = new Stage();
GraphEditor graphEditor = new DefaultGraphEditor();
Scene scene = new Scene(graphEditor.getView(), 800, 600);
secondaryStage.setScene(scene);
secondaryStage.show();
GModel model = GraphFactory.eINSTANCE.createGModel();
graphEditor.setModel(model);
addNodes(model);
If it's possible could you help me? 如果可以的话,你可以帮我吗?
Thank You 谢谢
Error on console: 控制台错误:
javafx.fxml.LoadException
:GraphEditorContainer
is not a valid type.javafx.fxml.LoadException
:GraphEditorContainer
不是有效的类型。
simply means that you didn't put the import for GraphEditorContainer
in the FXML file. 只是意味着您没有将
GraphEditorContainer
的导入放入FXML文件中。 Something like 就像是
<? import com.somecompany.somepackage.GraphEditorContainer ?>
near the top of the FXML file (with the other imports), obviously edited for the correct package name. 在FXML文件顶部附近(带有其他导入),显然已编辑为正确的包名称。
In the controller, it is always a mistake to initialize @FXML
-annotated fields, for obvious reasons, so replace 在控制器中,出于显而易见的原因,初始化
@FXML
字段始终是错误的,因此请替换
@FXML
private GraphEditorContainer graphEditorContainer = new GraphEditorContainer();
with 与
@FXML
private GraphEditorContainer graphEditorContainer ;
Using custom (or 3rd party) controls in SceneBuilder is covered in Adding a custom component to SceneBuilder 2.0 将自定义组件添加到SceneBuilder 2.0中介绍了在SceneBuilder中使用自定义(或第3方)控件。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.