import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import java.awt.event.ItemEvent; import java.awt.event.ItemListener; import java.awt.event.MouseAdapter; import java.awt.event.MouseEvent; import java.awt.event.MouseListener; import javafx.application.Application; import javafx.embed.swing.SwingNode; import javafx.scene.Scene; import javafx.scene.layout.Pane; import javafx.scene.layout.StackPane; import javafx.stage.Stage; import javax.swing.AbstractAction; import javax.swing.JComboBox; import javax.swing.JInternalFrame; import javax.swing.JLabel; import javax.swing.JMenu; import javax.swing.JMenuBar; import javax.swing.JMenuItem; import javax.swing.JPanel; import javax.swing.JPopupMenu; import javax.swing.SwingUtilities; /** * * @author andrey.rusakov */ public class FXTest2 extends Application { @Override public void start(final Stage stage) throws Exception { stage.setTitle("Fx window with panel"); Pane pane = new StackPane(); Scene scene = new Scene(pane, 300, 300); final SwingNode swingNode = new SwingNode(); init(swingNode); pane.getChildren().addAll(swingNode); stage.setScene(scene); stage.show(); } private void init(final SwingNode node) { SwingUtilities.invokeLater(new Runnable() { @Override public void run() { JPanel panel = new JPanel(); panel.add(new JLabel("Right click to show a popup menu.")); final JPopupMenu menu = new JPopupMenu(); for (int i = 1; i <= 5; i++) { menu.add(new JMenuItem(new AbstractAction("MenuItem " + i) { @Override public void actionPerformed(ActionEvent e) { System.out.println(e); } })); } panel.addMouseListener(new MouseAdapter() { @Override public void mousePressed(MouseEvent e) { maybeShowPopup(e); } @Override public void mouseReleased(MouseEvent e) { maybeShowPopup(e); } private void maybeShowPopup(MouseEvent e) { if (e.isPopupTrigger()) { menu.show(e.getComponent(), e.getX(), e.getY()); } } }); node.setContent(panel); } }); } public static void main(String[] args) { launch(args); } }