//package sample; 

import javafx.application.Application; 
import javafx.collections.FXCollections; 
import javafx.geometry.NodeOrientation; 
import javafx.geometry.Point2D; 
import javafx.scene.Scene; 
import javafx.scene.control.Button; 
import javafx.scene.control.ComboBox; 
import javafx.scene.control.Label; 
import javafx.scene.control.PopupControl; 
import javafx.scene.layout.HBox; 
import javafx.scene.layout.VBox; 
import javafx.stage.PopupWindow; 
import javafx.stage.Stage; 


public class Demo extends Application { 
    @Override 
    public void start(Stage stage) throws Exception { 
        Button b = new Button("Click me"); 
        b.setOnAction(event -> { 
            PopupControl popup = new PopupControl(); 
            popup.setAnchorLocation(PopupWindow.AnchorLocation.CONTENT_TOP_RIGHT); 
            popup.setAutoHide(true); 
            ComboBox<String> cb = new ComboBox<>(FXCollections.observableArrayList("foo", "bar")); 
            HBox box = new HBox(5, new Label("Select value"), cb); 
            box.setNodeOrientation(NodeOrientation.RIGHT_TO_LEFT); 
            // This is only to make the popup more visible. Removing it doesn't change the occurrence of the bug. 
            box.setStyle("-fx-background-color: derive(-fx-background, 30%); -fx-border-color: black; -fx-border-width: 1px;"); 
            popup.getScene().setRoot(box); 

            Point2D anchor = b.localToScreen(b.getWidth(), b.getHeight()); 
            popup.show(b, anchor.getX(), anchor.getY()); 
        }); 
        ComboBox<String> cb = new ComboBox<>(FXCollections.observableArrayList("foo", "bar")); 
        VBox vb = new VBox(10, b, cb); 
        vb.setNodeOrientation(NodeOrientation.RIGHT_TO_LEFT); 
        Scene scene = new Scene(vb, 200, 200); 
        stage.setScene(scene); 

        stage.show(); 
    } 


    public static void main(String[] args) throws Exception { 
        launch(args); 
    } 

} 