package testjavafx; import java.awt.BorderLayout; import javafx.application.Platform; import javafx.collections.FXCollections; 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.control.ComboBox; import javafx.scene.control.Label; import javafx.scene.layout.VBox; import javax.swing.JFrame; import javax.swing.JLabel; import javax.swing.SwingUtilities; public class ComboTest { JFrame frame; JFXPanel fxpanel; JFXPanel fxpanel2; public static void main( String[] args ) throws Exception { new ComboTest().init(); } private void init() throws Exception { fxpanel = new JFXPanel(); fxpanel2 = new JFXPanel(); SwingUtilities.invokeAndWait(new Runnable() { public void run() { initSwing(); } }); Platform.runLater(new Runnable() { public void run() { initJavaFX(); } }); } private void initSwing() { frame = new JFrame("JavaFX Test"); frame.getContentPane().add(new JLabel("JFXPanel ComboBox lockup..."), BorderLayout.NORTH); frame.getContentPane().add(fxpanel, BorderLayout.CENTER); frame.getContentPane().add(fxpanel2, BorderLayout.EAST); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.setSize(320, 240); frame.setVisible(true); } private void initJavaFX() { VBox b1 = new VBox(); final VBox b2 = new VBox(); b1.getChildren().add(new Label("Activate the dropdown on the combobox then click here.")); b1.getChildren().add(new Label("Then drag the window...")); b1.getChildren().add(new Label("The dropdown stays and it doesn't follow.")); b1.getChildren().add(new Label("Then activate the dropdown, and click this button:")); Button button = new Button("Hide ComboBox"); button.setOnAction(new EventHandler(){ public void handle(ActionEvent t) { b2.getChildren().setAll(new Label("Combo is gone")); } }); b1.getChildren().add(button); Button button2 = new Button("Show ComboBox"); button2.setOnAction(new EventHandler(){ public void handle(ActionEvent t) { b2.getChildren().setAll(new ComboBox(FXCollections.observableArrayList("One","Two","Three","Four"))); } }); b1.getChildren().add(button2); ComboBox combo = new ComboBox(FXCollections.observableArrayList("One","Two","Three","Four")); b2.getChildren().add(combo); fxpanel.setScene(new Scene(b1)); fxpanel2.setScene(new Scene(b2)); } }