简体   繁体   中英

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.

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. 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...

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. I tried it in two different ways, which result in an empty Tab , with no nodes and no error on the console.

First try

I tried putting into a Pane and set the GraphEditor inside the Pane.

My java code:

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:

<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. Maybe I got what they did wrong (I am a beginner in Java and JavaFX).

My java code:

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:

<?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.

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.

simply means that you didn't put the import for GraphEditorContainer in the FXML file. 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.

In the controller, it is always a mistake to initialize @FXML -annotated fields, for obvious reasons, so replace

@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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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