【发布时间】:2015-12-06 01:16:06
【问题描述】:
我需要制作一个在 JavaFX FXML 文件上生成图形的桌面应用程序。我在 Eclipse 中使用 mxGraph 库来构建图形,并使用 Scene Builder 来编辑 FXML 文件,但我无法使图形显示在 FXML 文件中,它仅在我使用 JFrame 时才有效。 当我这样运行时:
public class mxgraphteste extends JFrame{
public mxgraphteste(){
mxGraph grafo = new mxGraph();
Object parent = grafo.getDefaultParent();
Object v1 = grafo.insertVertex(parent, null, "Brazil", 100, 100, 50, 40);
Object v2 = grafo.insertVertex(parent, null, "Soccer", 240, 150, 50, 40);
Object a1 = grafo.insertEdge(parent, null, "loves", v1, v2);
mxGraphComponent graphComponent = new mxGraphComponent(grafo);
getContentPane().add(graphComponent);
}
public static void main(String[] args) {
mxgraphteste frame = new mxgraphteste();
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setSize(400, 320);
frame.setVisible(true);
}
}
它有效。 但我需要图表进入这个:
<AnchorPane prefHeight="600.0" prefWidth="800.0" xmlns="http://javafx.com/javafx/8.0.40" xmlns:fx="http://javafx.com/fxml/1" fx:controller="view.TelaPrincipalController">
<children>
<BorderPane fx:id="borderPane" layoutX="446.0" layoutY="141.0" prefHeight="600.0" prefWidth="800.0" AnchorPane.bottomAnchor="0.0" AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="0.0" AnchorPane.topAnchor="0.0">
<right>
<Pane fx:id="paineDireita" prefHeight="491.0" prefWidth="126.0" BorderPane.alignment="CENTER">
<children>
<Button fx:id="buttonNo" layoutX="37.0" layoutY="179.0" mnemonicParsing="false" onAction="#selecionarNo" text="Nó" />
<Button fx:id="buttonAresta" layoutX="28.0" layoutY="259.0" mnemonicParsing="false" text="Aresta" />
</children>
</Pane>
</right>
<center>
<Pane fx:id="paineCentro" prefHeight="200.0" prefWidth="200.0" BorderPane.alignment="CENTER" /> **~~~~~~~~~~~~~~~~ I NEED IT GO INSIDE THIS PANE ~~~~~~~~~~~~**
</center>
</BorderPane>
</children>
</AnchorPane>
我已经在使用 jdk8。我尝试关注Oracle's tutorial for Swing Content in JavaFX Applications,但无法将图表转换为 SwingNode。我找到了使用 JFXPanel 的解决方案,用于使用 JavaFX 的 Swing 应用程序,但它并没有起到相反的作用。 有谁知道我做错了什么或者我该如何解决这个问题? 谢谢!
【问题讨论】:
-
Swing GUI 对象应仅在event dispatch thread 上构造和操作,对于example。
-
嘿 Gabriela 我正在从事一个类似的项目,请写信给我; yogonza524@gmail.com 我可以帮你