When I have multiple SwingNodes in a panel (GridPane in a JFXPanel), I notice an extreme performance degradation. This doesn't appear to occur if there's only ONE SwingNode.
I realize that there's some expected degradation when mixing Swing and JavaFX, but this renders the application pretty much unusable (and I can't really change my industry circumstances; the legacy code is still in Swing, but we really want the new JavaFX graphing utilities).
This is running on Windows 7 on Java 8u60.
MCVE:
import javax.swing.*;
import javafx.application.Platform;
import javafx.embed.swing.JFXPanel;
import javafx.embed.swing.SwingNode;
import javafx.scene.Scene;
import javafx.scene.control.ToggleButton;
import javafx.scene.layout.ColumnConstraints;
import javafx.scene.layout.GridPane;
public class SwingNodeTest {
private static Scene createScene(JComponent button1, JComponent button2) {
GridPane pane = new GridPane();
pane.getColumnConstraints().add(new ColumnConstraints(100));
pane.getColumnConstraints().add(new ColumnConstraints(200));
SwingNode node1 = new SwingNode();
// Best practice to call SwingNode->setContent(...) on the EDT, but doesn't make
// a difference for the test.
node1.setContent(button1);
pane.add(node1, 0, 0);
ToggleButton node2 = new ToggleButton("2");
// Commenting out the above line and uncommenting the below lines cause EXTREME
// Performance degradation.
// SwingNode node2 = new SwingNode();
// node2.setContent(button2);
pane.add(node2, 1, 0);
return new Scene(pane);
}
public static void main(String[] args) {
SwingUtilities.invokeLater(new Runnable() {
@Override
public void run() {
JFrame frame = new JFrame();
JFXPanel panel = new JFXPanel();
frame.setSize(800, 600);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setContentPane(panel);
frame.setVisible(true);
JButton button1 = new JButton("1");
JToggleButton button2 = new JToggleButton("2");
Platform.runLater(new Runnable() {
@Override
public void run() {
final Scene scene = createScene(button1, button2);
panel.setScene(scene);
}
});
}
});
}
}
EDIT: Just realized after letting this MCVE run for a few minutes, I get OutOfMemoryErrors (GC overhead limit exceeded).