ComboBox keypress discrepancy

Abhinay Agarwal abhinay_agarwal at live.com
Tue Mar 24 11:36:54 UTC 2020


Hi All,

I have traced out the root cause responsible for the discrepancy between the behavior of ComboBox in JavaFX 8 vs later version. It turns out the change is in ListViewBehavior and was made under JEP-253[1]. ListView is used as the PopupContent Node in ComboBox.

In JDK 8, ListView doesn't have any event handler for TAB key press event [2]. In JDK 9, a default mapping was added to the ListViewBehavior [3][4] which added the key press event handlers for TAB and SHIFT + TAB. Unfortunately, I haven't been able to find the reasoning behind the change. Is there a JBS issue or mailing list discussion that can throw some light on it?

This discrepancy can also be reproduced with latest releases JDK 8 and JavaFX 14.

Best regards,
Abhinay


[1] https://bugs.openjdk.java.net/browse/JDK-8076423
[2] https://github.com/openjdk/jfx/blob/48086c72c27237552d8794ff72b2e152a9a7cea1/modules/controls/src/main/java/com/sun/javafx/scene/control/behavior/ListViewBehavior.java#L65
[3] https://github.com/openjdk/jfx/blob/master/modules/javafx.controls/src/main/java/com/sun/javafx/scene/control/behavior/ListViewBehavior.java#L81
[4] https://github.com/openjdk/jfx/blob/master/modules/javafx.controls/src/main/java/com/sun/javafx/scene/control/behavior/FocusTraversalInputMap.java#L53

P.S. I sincerely hope everyone in this mailing list are healthy and safe!

________________________________
From: Abhinay Agarwal <abhinay_agarwal at live.com>
Sent: Sunday, March 8, 2020 1:51 PM
To: Dirk Lemmermann <dlemmermann at gmail.com>
Cc: openjfx-dev at openjdk.java.net <openjfx-dev at openjdk.java.net>
Subject: Re: ComboBox keypress discrepancy

Hi Dirk,

Exactly. The TAB key press event not firing at all seems fishy.

-- Abhinay

________________________________
From: Dirk Lemmermann <dlemmermann at gmail.com>
Sent: Friday, March 6, 2020 2:55 PM
To: Abhinay Agarwal <abhinay_agarwal at live.com>
Cc: openjfx-dev at openjdk.java.net <openjfx-dev at openjdk.java.net>
Subject: Re: ComboBox keypress discrepancy

Regarding expected behaviour: in native combo boxes / dropdowns on Mac the TAB key is doing nothing when the popup is open. If you want to select an item you need to use the arrow keys. So I guess that is what I would expect for navigating the element. But that does not mean that the key event can’t fire, right? Some subclass / custom control might have a need for it.

Dirk



Am 06.03.2020 um 05:59 schrieb Abhinay Agarwal <abhinay_agarwal at live.com<mailto:abhinay_agarwal at live.com>>:

Hi Dirk,

Thanks for reaching out. As stated earlier, I want to know what exactly is causing this change in behaviour. I also want to know what is the expected behaviour in this case: should TAB key press trigger when the popupwindow is showing?

-- Abhinay
________________________________
From: Dirk Lemmermann <dlemmermann at gmail.com<mailto:dlemmermann at gmail.com>>
Sent: Thursday, March 5, 2020 6:39 PM
To: Abhinay Agarwal <abhinay_agarwal at live.com<mailto:abhinay_agarwal at live.com>>
Cc: openjfx-dev at openjdk.java.net<mailto:openjfx-dev at openjdk.java.net> <openjfx-dev at openjdk.java.net<mailto:openjfx-dev at openjdk.java.net>>
Subject: Re: ComboBox keypress discrepancy

So what info do you need? What test do you want us to run?

I ran it on MacOS X with Java 14ea and I DO NOT see the „TAB“ output.

Dirk

Am 05.03.2020 um 11:43 schrieb Abhinay Agarwal <abhinay_agarwal at live.com<mailto:abhinay_agarwal at live.com>>:

import javafx.application.Application;
import javafx.scene.Scene;
import javafx.scene.control.ComboBox;
import javafx.scene.input.KeyEvent;
import javafx.scene.layout.BorderPane;
import javafx.stage.Stage;

public class Main extends Application {

   @Override
   public void start(Stage primaryStage) {
       final ComboBox<String> stringComboBox = new ComboBox<>();
       stringComboBox.getItems().addAll("John", "Jacob", "Schmidt");
       stringComboBox.addEventHandler(KeyEvent.KEY_PRESSED, kp -> System.out.println(kp.getCode()));

       final Scene scene = new Scene(new BorderPane(stringComboBox), 300, 275);
       primaryStage.setScene(scene);
       primaryStage.show();
   }

   public static void main(String[] args) {
       launch(args);
   }
}



More information about the openjfx-dev mailing list