I am trying to integrate JavaFX in an existing Swing application. I am following this tutorial, so before actually integrating it into the existing application, I can have an environment with reduced complexity and try if it is working before moving further. I was following the tutorial at the official website of Oracle/JavaFX at http://docs.oracle.com/javafx/2/swing/swing-fx-interoperability.htm . Especially, I was also downloading the source code of the example SwingInterop.zip and still getting the same exception:
run:
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)
I've found a thread in StackOverflow (UnsatisfiedLinkError when running mvn jfx:run with IntelliJ) which might be the one I'm looking for. Is this what I need to do? I tried but it didn't work, probably because I did not do it properly?
It has to do with performing the operation in the correct thread,because as far as I understand Swing and JavaFX are running in two different threads: the portion of code (which is the one in the example, not even written by me) which leeds to this issue might be :
@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));
}
});
}