繁体   English   中英

如何将.jar文件的对象插入Scene Builder?

[英]How to insert an object of a .jar file into Scene Builder?

我正在为我的大师编写一个仿真软件,它包含一个“图形容器”,您可以在其中链接节点以根据我链接的内容生成方程式。 这些方程将使我能够模拟我的模型。 我为此使用Java 8和JavaFX,以及Scene Builder和FXML。

在网上搜索时,我发现了Graph-Editor( https://github.com/tesis-dynaware/graph-editor ),它将对我的需求有所帮助。 按照项目站点上的教程,我可以复制它并使其运行。 但是在我的软件上,我不需要像教程中那样使用图来创建新窗口-而是,我想拥有一个TabPane,使我能够根据需要创建尽可能多的模型,例如文本编辑器,如果需要的话希望我可以将其保存在XML等上...

我的问题是:我试图将教程中的图形放在它们在教程上所做的Tab (使用getView方法),但它不起作用。 我以两种不同的方式进行了尝试,这导致一个空的Tab ,在控制台上没有节点并且没有错误。

第一次尝试

我尝试放入窗格中并将GraphEditor设置在窗格中。

我的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);

}

我的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>

第二种方式

我已经看到了他们的演示源代码,并且我了解到他们创建了GraphEditorContainer对象的实例,然后他们的FXML文件具有该GraphEditorContainer ,但是我的方式不起作用。 也许我弄明白了他们做错了什么(我是Java和JavaFX的初学者)。

我的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);

}

我的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>

我可以将打开窗口并绘制节点的代码放在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);

如果可以的话,你可以帮我吗?

谢谢

控制台错误:

javafx.fxml.LoadExceptionGraphEditorContainer不是有效的类型。

只是意味着您没有将GraphEditorContainer的导入放入FXML文件中。 就像是

<? import com.somecompany.somepackage.GraphEditorContainer ?>

在FXML文件顶部附近(带有其他导入),显然已编辑为正确的包名称。

在控制器中,出于显而易见的原因,初始化@FXML字段始终是错误的,因此请替换

@FXML
private GraphEditorContainer graphEditorContainer = new    GraphEditorContainer();

@FXML
private GraphEditorContainer graphEditorContainer ;

将自定义组件添加到SceneBuilder 2.0中介绍了在SceneBuilder中使用自定义(或第3方)控件。

暂无
暂无

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

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