package sampleswt;

import javax.swing.JFrame;

import javafx.application.Platform;
import javafx.collections.FXCollections;
import javafx.embed.swing.JFXPanel;
import javafx.geometry.Pos;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.control.ColorPicker;
import javafx.scene.control.ComboBox;
import javafx.scene.layout.BorderPane;
import javafx.scene.layout.HBox;
import javafx.stage.Stage;

public class SwingDummy extends JFrame {
    public SwingDummy() {
        setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        final JFXPanel fxPanel = new JFXPanel();
        add(fxPanel);

        Platform.runLater(new Runnable() {
            @Override
            public void run() {
                initFX(fxPanel);
            }
        });
    }

    private static void initFX(JFXPanel fxPanel) {
        // This method is invoked on JavaFX thread
        Scene scene = createScene();
        fxPanel.setScene(scene);
    }

    private static Scene createScene() {
        ColorPicker colorPicker = new ColorPicker();
        ComboBox<String> combo = new ComboBox<>(FXCollections.observableArrayList("A", "B", "C"));
        Button bu = new Button("Open Window");
        bu.setOnAction(e -> {
            Stage child = new Stage();
            child.initOwner(bu.getScene().getWindow());
            child.setScene(new Scene(new BorderPane(new Button("I should not go to the back")), 400, 400));
            child.show();
        });

        HBox box = new HBox(10);
        box.setAlignment(Pos.CENTER);
        box.getChildren().addAll(colorPicker, combo, bu);
        return new Scene(new BorderPane(box), 640, 640);
    }

    public static void main(String[] args) {
        SwingDummy s = new SwingDummy();
        s.setBounds(100, 100, 1000, 800);
        s.setVisible(true);
    }
}
