package es.carlosmontero.swt; import javafx.collections.FXCollections; import javafx.collections.ObservableList; import javafx.embed.swt.FXCanvas; import javafx.scene.Scene; import javafx.scene.chart.PieChart; import org.eclipse.swt.SWT; import org.eclipse.swt.layout.GridData; import org.eclipse.swt.layout.GridLayout; import org.eclipse.swt.widgets.Button; import org.eclipse.swt.widgets.Display; import org.eclipse.swt.widgets.Event; import org.eclipse.swt.widgets.Label; import org.eclipse.swt.widgets.Listener; import org.eclipse.swt.widgets.Shell; public class MultipleDisplaysAndJavaFX { public static void main(final String[] args) { final Display display = new Display(); final Shell shell = new Shell(display); shell.setLayout(new GridLayout()); shell.setText("Main shell"); final Button simpleDisplayButton = new Button(shell, SWT.NONE); simpleDisplayButton.setText("Simple Display"); simpleDisplayButton.addListener(SWT.Selection, new Listener() { @Override public void handleEvent(final Event event) { new Thread(new Runnable() { @Override public void run() { final Display simpleDisplay = new Display(); final Shell simpleShell = new Shell(simpleDisplay); simpleShell.setText("Simple Display"); simpleShell.setLayout(new GridLayout()); new Label(simpleShell, SWT.NONE).setText("This is a label into a SimpleShell"); simpleShell.open(); while (!simpleShell.isDisposed()) { if (!simpleDisplay.readAndDispatch()) { simpleDisplay.sleep(); } } simpleDisplay.dispose(); } }).start(); } }); final Button fxcanvasDisplayButton = new Button(shell, SWT.NONE); fxcanvasDisplayButton.setText("Display with FXCanvas"); fxcanvasDisplayButton.addListener(SWT.Selection, new Listener() { @Override public void handleEvent(final Event event) { new Thread(new Runnable() { @Override public void run() { final Display fxcanvasDisplay = new Display(); final Shell fxcanvasShell = new Shell(fxcanvasDisplay); fxcanvasShell.setText("Shell with FXCanvas"); fxcanvasShell.setLayout(new GridLayout()); final FXCanvas fxCanvas = new FXCanvas(fxcanvasShell, SWT.NONE); fxCanvas.setLayoutData(new GridData(GridData.FILL)); // Simple chart code from ensemble final ObservableList pieChartData = FXCollections.observableArrayList( new PieChart.Data("Sun", 20), new PieChart.Data("IBM", 12), new PieChart.Data("HP", 25), new PieChart.Data("Dell", 22), new PieChart.Data("Apple", 30) ); final PieChart chart = new PieChart(pieChartData); chart.setClockwise(false); final Scene scene = new Scene(chart); fxCanvas.setScene(scene); fxcanvasShell.open(); while (!fxcanvasShell.isDisposed()) { if (!fxcanvasDisplay.readAndDispatch()) { fxcanvasDisplay.sleep(); } } fxcanvasDisplay.dispose(); } }).start(); } }); shell.open(); while (!shell.isDisposed()) { if (!display.readAndDispatch()) { display.sleep(); } } display.dispose(); } }