package hello; import java.awt.BorderLayout; import java.awt.Dimension; import javafx.application.Platform; import javafx.embed.swing.JFXPanel; import javafx.scene.Node; import javafx.scene.Scene; import javafx.scene.control.Button; import javafx.scene.layout.HBox; import javax.swing.JApplet; import javax.swing.JFrame; import javax.swing.SwingUtilities; import javax.swing.UIManager; /** * * @author diego.cirujano-cuesta */ public class JavaFXSwingApplication2 extends JApplet { private static JFXPanel fxContainer; /** * @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 2 in Swing"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); JApplet applet = new JavaFXSwingApplication2(); 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(300, 250)); add(fxContainer, BorderLayout.CENTER); // create JavaFX scene Platform.runLater(() -> createScene()); } private void createScene() { Button btn = new Button(); btn.setText("Hello'"); initPopup(btn); Button btn2 = new Button(); btn2.setText("beautiful'"); initPopup(btn2); Button btn3 = new Button(); btn3.setText("World'"); initPopup(btn3); HBox root = new HBox(); root.getChildren().addAll(btn, btn2, btn3); fxContainer.setScene(new Scene(root)); } private void initPopup(Node newValue) { javafx.stage.Popup popup = new javafx.stage.Popup(); popup.setAutoHide(true); Button btn = new Button("popup"); popup.getContent().add(btn); newValue.setOnMouseEntered(mouseEvent -> { popup.show(newValue, mouseEvent.getScreenX(), mouseEvent.getScreenY()); btn.requestFocus(); }); newValue.setOnMouseExited(mouseEvent -> { if (popup.isShowing()) { popup.hide(); } }); } }