Skip to Main Content

Java SE (Java Platform, Standard Edition)

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Interested in getting your voice heard by members of the Developer Marketing team at Oracle? Check out this post for AppDev or this post for AI focus group information.

Button is not fired on enter key in JavaFX 8

WhiteAntelopeSep 3 2014 — edited Sep 8 2014

Hi,

with the switch of the JVM version in our project, it turned out that the default behavior of Button has changed from JavaFX 2.2 to JavaFX 8. The button action is not fired on pressing the Enter key, only on pressing space.

Sample:

public class ButtonTest extends Application

{

    @Override

    public void start(Stage primaryStage) throws Exception

    {

        Button l_button = new Button("Hit me");

        l_button.setOnAction(new EventHandler<ActionEvent>()

        {

           

            @Override

            public void handle(ActionEvent event)

            {

                System.out.println("auau");

            }

        });

        primaryStage.setScene(new Scene(l_button));

        primaryStage.show();

    }

   

    public static void main(String[] args)

    {

        launch(args);

    }

}

Run the sample Application in Java 7 with JavaFX 2.2: both pressing Enter and Space print "auau" to the console if the button is focused.

Run the sample Application in Java 8: only pressing Space prints "auau"

How can this be? Hitting a focused button on Enter is a standard behavior on Windows platforms.

Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Oct 6 2014
Added on Sep 3 2014
4 comments
3,632 views