无法在Java Swing中集成JavaFX

时间:2014-01-21 12:42:50

标签: java swing netbeans javafx java-7

我正在尝试将JavaFX集成到现有的Swing应用程序中。我正在学习本教程,因此在将其实际集成到现有应用程序之前,我可以拥有一个复杂性降低的环境,并尝试在进一步移动之前工作。我在http://docs.oracle.com/javafx/2/swing/swing-fx-interoperability.htm的Oracle / JavaFX官方网站上关注了该教程。特别是,我还下载了示例SwingInterop.zip的源代码,但仍然得到了相同的异常:

运行:

    Exception in thread "Thread-1" java.lang.UnsatisfiedLinkError: com.sun.glass.ui.win.WinApplication._submitForLaterInvocation(Ljava/lang/Runnable;)V
    at com.sun.glass.ui.win.WinApplication._submitForLaterInvocation(Native Method)
    at com.sun.glass.ui.win.WinApplication.submitForLaterInvocation(WinApplication.java:215)
    at com.sun.glass.ui.InvokeLaterDispatcher.run(InvokeLaterDispatcher.java:101)

我在StackOverflow(UnsatisfiedLinkError when running mvn jfx:run with IntelliJ)中找到了一个可能是我正在寻找的线程。这是我需要做的吗?我试过但它没有用,可能是因为我做得不好?

它与在正确的线程中执行操作有关,因为据我所知,Swing和JavaFX在两个不同的线程中运行:代码部分(示例中的部分,甚至不是我编写的)这个问题的利益可能是:

@Override
public void init() {
    tableModel = new JTableDataInOut();
    // create javafx panel for charts
    chartFxPanel.setPreferredSize(new Dimension(PANEL_WIDTH_INT, PANEL_HEIGHT_INT));

    //create JTable
    JTable table = new JTable(tableModel);
    table.setAutoCreateRowSorter(true);
    table.setGridColor(Color.DARK_GRAY);
    SwingInterop.DecimalFormatRenderer renderer
            = new SwingInterop.DecimalFormatRenderer();
    renderer.setHorizontalAlignment(JLabel.RIGHT);
    for (int i = 0; i < table.getColumnCount(); i++) {
        table.getColumnModel().getColumn(i).setCellRenderer(renderer);
    }
    JScrollPane tablePanel = new JScrollPane(table);
    tablePanel.setPreferredSize(new Dimension(PANEL_WIDTH_INT, TABLE_PANEL_HEIGHT_INT));
    JPanel chartTablePanel = new JPanel();
    chartTablePanel.setLayout(new BorderLayout());

    //Create split pane that holds both the bar chart and table
    JSplitPane jsplitPane = new JSplitPane(JSplitPane.VERTICAL_SPLIT);
    jsplitPane.setTopComponent(chartTablePanel);
    jsplitPane.setBottomComponent(tablePanel);
    jsplitPane.setDividerLocation(410);
    chartTablePanel.add(chartFxPanel, BorderLayout.CENTER);

    //Add the split pane to the content pane of the application
    add(jsplitPane, BorderLayout.CENTER);

    Platform.runLater(new Runnable() {

        @Override
        public void run() {
            BarChart chart = createBarChart();
            chartFxPanel.setScene(new Scene(chart));
        }
    });
}

0 个答案:

没有答案