1818import javax .swing .JPanel ;
1919import javax .swing .SwingUtilities ;
2020
21+ import javafx .event .EventHandler ;
22+ import javafx .scene .Scene ;
23+ import javafx .scene .control .Button ;
24+ import javafx .scene .control .Label ;
25+ import javafx .scene .layout .StackPane ;
26+ import javafx .stage .Stage ;
27+ import javafx .embed .swing .JFXPanel ;
28+
29+
2130import org .json .JSONArray ;
2231import org .json .JSONObject ;
2332
@@ -50,10 +59,15 @@ public class LayoutServiceDemo implements DesktopStateListener {
5059 private JSONArray serviceConfig = new JSONArray ();
5160 private Map <String , LayoutFrame > childFrames = new HashMap ();
5261 private WindowAdapter childFrameCleanListener ;
62+ private JButton btnCreateJavaFxWindow ;
5363
5464 LayoutServiceDemo () {
5565 try {
5666 this .createMainWindow ();
67+
68+ //init javafx
69+ new JFXPanel ();
70+
5771 this .launchOpenfin ();
5872
5973 this .childFrameCleanListener = new WindowAdapter () {
@@ -110,13 +124,22 @@ public void actionPerformed(ActionEvent e) {
110124 }
111125 }
112126 });
127+ this .btnCreateJavaFxWindow = new JButton ("Create JavaFX Window" );
128+ this .btnCreateJavaFxWindow .addActionListener (new ActionListener () {
129+ @ Override
130+ public void actionPerformed (ActionEvent e ) {
131+ createJavaFxWindow ();
132+ }
133+ });
113134 this .btnCreateOpenfinWindow .setEnabled (false );
114135 this .btnCreateJavaWindow .setEnabled (false );
136+ this .btnCreateJavaFxWindow .setEnabled (false );
115137 JPanel contentPnl = new JPanel (new BorderLayout (10 , 10 ));
116138 contentPnl .setBorder (BorderFactory .createEmptyBorder (10 , 10 , 10 , 10 ));
117139 JPanel pnl = new JPanel (new FlowLayout (FlowLayout .CENTER ));
118140 pnl .add (btnCreateOpenfinWindow );
119- pnl .add (btnCreateJavaWindow );
141+ pnl .add (btnCreateJavaWindow );
142+ pnl .add (btnCreateJavaFxWindow );
120143
121144 contentPnl .add (new JLabel ("Undock Openfin windows with global hotkey (CTRL+SHIFT+U or CMD+SHIFT+U)" ),
122145 BorderLayout .NORTH );
@@ -174,6 +197,7 @@ public void onSuccess(Ack ack) {
174197 public void run () {
175198 btnCreateOpenfinWindow .setEnabled (true );
176199 btnCreateJavaWindow .setEnabled (true );
200+ btnCreateJavaFxWindow .setEnabled (true );
177201 }
178202 });
179203 }
@@ -190,6 +214,38 @@ void createJavaWindow() throws DesktopException {
190214 this .childFrames .put (windowName , frame );
191215 frame .addWindowListener (this .childFrameCleanListener );
192216 }
217+
218+ void createJavaFxWindow () {
219+ String windowName = UUID .randomUUID ().toString ();
220+ javafx .application .Platform .runLater (new Runnable () {
221+ @ Override
222+ public void run () {
223+ Button undock = new Button ("undock" );
224+
225+ StackPane secondaryLayout = new StackPane ();
226+ secondaryLayout .getChildren ().add (undock );
227+
228+ Scene secondScene = new Scene (secondaryLayout , 230 , 100 );
229+
230+ // New window (Stage)
231+ Stage newWindow = new Stage ();
232+ newWindow .setTitle (windowName );
233+ newWindow .setScene (secondScene );
234+
235+ // Set position of second window, related to primary window.
236+ newWindow .setX (200 );
237+ newWindow .setY (150 );
238+ newWindow .show ();
239+
240+ try {
241+ new ExternalWindowObserver (desktopConnection .getPort (), appUuid , windowName , newWindow , null );
242+ } catch (DesktopException e ) {
243+ // TODO Auto-generated catch block
244+ e .printStackTrace ();
245+ }
246+ }
247+ });
248+ }
193249
194250 void createOpenfinWindow () {
195251 try {
@@ -222,6 +278,7 @@ public void onReady() {
222278 this .application = Application .wrap (appUuid , this .desktopConnection );
223279 btnCreateOpenfinWindow .setEnabled (true );
224280 btnCreateJavaWindow .setEnabled (true );
281+ btnCreateJavaFxWindow .setEnabled (true );
225282 }
226283
227284 @ Override
0 commit comments