TextFields are not editable while the PopOver is open

Issue #844 resolved
Eric Baisch
created an issue

I am trying to use a popover at the end of a textfield with the text inside the TextField. The TextField is not editable while the PopOver is open. I am posting a sample down below of the issue.

public class Test extends Application {

    @Override
    public void start(Stage primaryStage) {


        TextField textField = new TextField("Mouse mouse over me");
        TextArea textArea = new TextArea(textField.getText());
        textArea.setEditable(false);
        PopOver popOver = new PopOver(textArea);
        textField.setOnMouseEntered(mouseEvent -> {
            //Show PopOver when mouse enters label
            popOver.show(textField);
            textField.requestFocus();
        });

        StackPane root = new StackPane();
        root.getChildren().add(textField);

        Scene scene = new Scene(root, 300, 250);

        primaryStage.setTitle("Hello World!");
        primaryStage.setScene(scene);
        primaryStage.show();
    }

    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) {
        launch(args);
    }
}

Comments (5)

  1. Abhinay Agarwal

    You must set the focusTraversable property of the TextArea to false. The following snippet should work:

    TextField textField = new TextField("Mouse mouse over me");
    TextArea textArea = new TextArea(textField.getText());
    textArea.setEditable(false);
    textArea.setFocusTraversable(false);
    PopOver popOver = new PopOver(textArea);
    
  2. Eric Baisch reporter

    That worked. The only thing is that if I keep brining up the popOver and hiding it, the memory keeps going up and it never goes back down. Do you see where the memory leak could be coming from?

           TextField textField = new TextField("Mouse mouse over me");
            TextArea textArea = new TextArea(textField.getText());
            PopOver popOver = new PopOver(textArea);
            textArea.setFocusTraversable(false);
            textField.setOnMouseEntered(mouseEvent -> {
                textArea.setText(textField.getText());
                //Show PopOver when mouse enters label
                popOver.show(textField);
            });
    
            textField.setOnMouseExited(event -> {
                popOver.hide();
            });
    
            StackPane root = new StackPane();
            root.getChildren().add(textField);
    
            Scene scene = new Scene(root, 300, 250);
    
            primaryStage.setTitle("Hello World!");
            primaryStage.setScene(scene);
            primaryStage.show();
    
  3. Log in to comment