/* * To change this license header, choose License Headers in Project Properties. * To change this template file, choose Tools | Templates * and open the template in the editor. */ package javafx_swing_application; import java.awt.BorderLayout; import java.awt.Dimension; import java.awt.Label; import java.awt.Color; import javafx.application.Platform; import javafx.embed.swing.JFXPanel; import javafx.event.ActionEvent; import javafx.event.EventHandler; import javafx.scene.Scene; import javafx.scene.control.Button; import javafx.scene.layout.StackPane; import javax.swing.JApplet; import javax.swing.JFrame; import javax.swing.JFileChooser; import javax.swing.JLabel; import javax.swing.ImageIcon; import javax.swing.SwingUtilities; import javax.swing.BorderFactory; import javax.swing.GroupLayout.Group; import javax.swing.UIManager; import javax.swing.border.Border; import javax.swing.border.MatteBorder; import javafx.application.Platform; import javafx.embed.swing.JFXPanel; import javafx.scene.Scene; import javafx.scene.image.Image; import javafx.scene.text.Font; import javafx.scene.text.Text; import javafx.stage.FileChooser; import javax.swing.JFrame; import javax.swing.JOptionPane; import javax.swing.SwingUtilities; import javax.swing.filechooser.FileNameExtensionFilter; /** * * RJM Programming - February, 2015 */ public class JavaFX_Swing_Application extends JApplet { private static final int JFXPANEL_WIDTH_INT = 600; private static final int JFXPANEL_HEIGHT_INT = 500; private static JFXPanel fxContainer; private static Button btn2; public static int returnVal; /** * @param args the command line arguments */ public static void main(String[] args) { SwingUtilities.invokeLater(new Runnable() { @Override public void run() { try { UIManager.setLookAndFeel("com.sun.java.swing.plaf.nimbus.NimbusLookAndFeel"); } catch (Exception e) { } JFrame frame = new JFrame("JavaFX in Swing"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); JApplet applet = new JavaFX_Swing_Application(); applet.init(); frame.setContentPane(applet.getContentPane()); frame.pack(); frame.setLocationRelativeTo(null); frame.setVisible(true); applet.start(); } }); } @Override public void init() { fxContainer = new JFXPanel(); fxContainer.setPreferredSize(new Dimension(JFXPANEL_WIDTH_INT, JFXPANEL_HEIGHT_INT)); add(fxContainer, BorderLayout.CENTER); // create JavaFX scene Platform.runLater(new Runnable() { @Override public void run() { initFX(fxContainer); //createScene(); } }); } private static void initFX(JFXPanel fxPanel) { // This method is invoked on the JavaFX thread Scene scene = createScene(); fxPanel.setScene(scene); } private static Scene createScene() { StackPane root = new StackPane(); Scene scene = new Scene(root); Text text = new Text(); text.setX(40); text.setY(100); text.setFont(new Font(25)); text.setText(" Welcome to JavaFX!\n\n\n\n\n From RJM Programming"); root.getChildren().add(text); final Button btn2 = new Button(); btn2.setLayoutX(200); btn2.setLayoutY(150); btn2.setText("Say big\n\n\n 'Hello World of JavaFX!'"); btn2.setOnAction(new EventHandler() { @Override public void handle(ActionEvent event) { System.out.println("Hello World of JavaFX!"); btn2.setText("Why, thank you\n\n\n ... what a relief!"); } }); root.getChildren().add(btn2); Button btn3 = new Button(); btn3.setText("What's that again?"); btn3.setOnAction(new EventHandler() { @Override public void handle(ActionEvent event) { System.out.println("Hello World of JavaFX! Again"); btn2.setText("Why, thank you again\n\n\n ... what a relief, again!"); } }); root.getChildren().add(btn3); return (scene); } }