// Collection of code snippets by Arne Vajhøj 
// (from articles on eksperten.dk / vajhoej.dk written sometime between 2004 and now) 
package demo;

import javafx.application.Platform;
import javafx.embed.swing.JFXPanel;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.control.Label;
import javafx.scene.layout.BorderPane;

import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.SwingUtilities;
import java.awt.BorderLayout;
import java.awt.Dimension;
import java.awt.GridLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

public class MixedGUI extends JFrame {
    public MixedGUI() {
        setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        setTitle("Mixed GUI");
        getContentPane().setLayout(new GridLayout(2, 1));
        JButton swinghi = new JButton("Swing hi");
        JLabel swingtxt = new JLabel("                                                 ");
        swinghi.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent e) {
                swingtxt.setText("Hi from Swing");
            }
        });
        JPanel p = new JPanel();
        p.setLayout(new BorderLayout());
        p.add(swinghi, BorderLayout.WEST);
        p.add(swingtxt, BorderLayout.EAST);
        getContentPane().add(p);
        JFXPanel fxp = new JFXPanel();
        getContentPane().add(fxp);
        pack();
        Platform.runLater(() -> {
            Button javafxhi = new Button("JavaFX hi");
            Label javafxtxt = new Label("                                                 ");
            javafxhi.setOnAction((e) -> {
                javafxtxt.setText("Hi from JavaFX");
            });
            BorderPane bp = new BorderPane();
            bp.setLeft(javafxhi);
            bp.setRight(javafxtxt);
            Scene scn = new Scene(bp);
            fxp.setScene(scn);
        });
    }
    public static void main(String[] args) {
        SwingUtilities.invokeLater(new Runnable() {
            public void run() {
                JFrame f = new MixedGUI();
                f.setVisible(true);
            }
        });
    }
}
