Problem with the accents in textfield in popover

3

I am using a PopOver that contains a TextField and it is displayed when the user clicks on the imageView of a CustomTextField. When I click inside the internal TextField, everything goes well until I insert an accented vowel, which to my surprise is picked up by the external TextField instead of the internal one.

I show images of what happens, when popover.show(imageView)

When the popover is displayed from a button there is no problem popover.show(button)

I do not know, it seems to be a bug. If anyone has any idea why this happens, I would appreciate any help. Thanks

EDIT: Here I reproduce an example of code in which the effect that I comment is produced, when you introduce a vowel with a tilde in internal textfield, it does not appear in the internal one, but in the external one.

public class PopOverTest extends Application {

    @Override
    public void start(Stage primaryStage) {

        CustomTextField externo = new CustomTextField();
        ImageView imgView = new ImageView(new Image("test/image.png"));
        externo.setLeft(imgView);

        CustomTextField interno = new CustomTextField();

        PopOver popOver = new PopOver();
        popOver.setContentNode(interno);

        imgView.setOnMouseClicked(e -> {
            popOver.show(imgView);

        });


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

        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);
    }

}
    
asked by axiorema 22.10.2016 в 22:32
source

1 answer

0

I have found a solution to this problem.

It consists in changing the KeyEventDispather of the external TextField by the internal one and works perfectly.

externo.setEventDispatcher(interno.getEventDispatcher());

we previously saved it to be able to return it later:

EventDispatcher dispatcher = externo.getEventDispatcher();

To extend the example for the case where there is more than one internal TextField, the EventDispatcher must be changed for each TextField when it receives the focus and return it when it loses it.

I show the complete example with two internal TextFields:

public class PopOverTest extends Application {

    @Override
    public void start(Stage primaryStage) {

        CustomTextField externo = new CustomTextField();
        ImageView imgView = new ImageView(new Image("test/image.png"));
        externo.setLeft(imgView);


        CustomTextField interno1 = new CustomTextField();
        CustomTextField interno2 = new CustomTextField();
        VBox box = new VBox(5, interno1, interno2);

        PopOver popOver = new PopOver();
        popOver.setContentNode(box);
        popOver.setArrowLocation(PopOver.ArrowLocation.TOP_LEFT);

        EventDispatcher dispatcher = externo.getEventDispatcher();

        imgView.setOnMouseClicked(e -> {
            popOver.show(imgView);
        });


        interno1.focusedProperty().addListener((observable,  oldValue,  newValue) -> {
            if (newValue) {
                externo.setEventDispatcher(interno1.getEventDispatcher());
            } else {
                externo.setEventDispatcher(dispatcher);
            }
        });

        interno2.focusedProperty().addListener((observable,  oldValue,  newValue) -> {
            if (newValue) {
                externo.setEventDispatcher(interno2.getEventDispatcher());
            } else {
                externo.setEventDispatcher(dispatcher);
            }
        });


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

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

        primaryStage.setTitle("PopOver Test");
        primaryStage.setScene(scene);
        primaryStage.show();
    }

    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) {
        launch(args);
    }
}
    
answered by 26.10.2016 / 14:24
source