簡體   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