-
Bug
-
Resolution: Won't Fix
-
P4
-
None
-
jfx23, jfx24
-
generic
-
generic
ADDITIONAL SYSTEM INFORMATION :
$ java -version
openjdk version "23" 2024-09-17
OpenJDK Runtime Environment (build 23+37-2369)
OpenJDK 64-Bit Server VM (build 23+37-2369, mixed mode, sharing)
$ uname -a
Linux bastion 6.1.100-un-def-alt1 #1 SMP PREEMPT_DYNAMIC Fri Aug 2 06:40:54 UTC 2024 x86_64 GNU/Linux
A DESCRIPTION OF THE PROBLEM :
Ctrl+keys are handled differently by Scene if TextField has focus.
Option1 : scene event filter handles all keys
Option2: scene accelerators skips some keys like in example shown
STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
1. Set JAVA_HOME and PATH to jdk-23
2, Build and Launch
mvn clean package exec:exec
3, Press buttons: Ctrl+], Ctrl+[, Ctrl+\
All keys are reflected in label content.
4. Comment Option 1 and uncomment Option 2.
Now Ctrl+\ does not work
EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
All accelerators are handled properly
ACTUAL -
Some accelerators are not handled.
---------- BEGIN SOURCE ----------
Full project: https://github.com/petr-panteleyev/bug_shortcuts
=== shortcuts/Main.java ===
package shortcuts;
import javafx.application.Application;
import javafx.application.Platform;
import javafx.scene.control.ButtonType;
import javafx.scene.control.Dialog;
import javafx.scene.control.Label;
import javafx.scene.control.TextField;
import javafx.scene.input.KeyCode;
import javafx.scene.input.KeyCodeCombination;
import javafx.scene.input.KeyEvent;
import javafx.scene.layout.VBox;
import javafx.stage.Stage;
import java.util.Map;
import static javafx.scene.input.KeyCombination.SHORTCUT_DOWN;
class MainDialog extends Dialog {
private final Label label = new Label();
private final TextField textField = new TextField();
public MainDialog() {
getDialogPane().setContent(new VBox(10, label, textField));
getDialogPane().getButtonTypes().add(ButtonType.CLOSE);
Map<KeyCodeCombination, Runnable> accelerators = Map.of(
new KeyCodeCombination(KeyCode.BACK_SLASH, SHORTCUT_DOWN), () -> label.setText("BACK_SLASH"),
new KeyCodeCombination(KeyCode.CLOSE_BRACKET, SHORTCUT_DOWN), () -> label.setText("CLOSE_BRACKET"),
new KeyCodeCombination(KeyCode.OPEN_BRACKET, SHORTCUT_DOWN), () -> label.setText("OPEN_BRACKET")
);
/* Option 1 */
getDialogPane().getScene().addEventFilter(KeyEvent.KEY_RELEASED, event -> {
for (var a : accelerators.entrySet()) {
if (a.getKey().match(event)) {
a.getValue().run();
event.consume();
}
}
});
/* Option 2 */
// getDialogPane().getScene().getAccelerators().putAll(accelerators);
Platform.runLater(textField::requestFocus);
}
}
public class Main extends Application {
@Override
public void start(Stage stage) throws Exception {
new MainDialog().showAndWait();
}
public static void main(String[] args){
launch(args);
}
}
=== module-info.java ===
open module shortcuts {
requires javafx.controls;
exports shortcuts;
}
=== pom.xml ===
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>bugreports</groupId>
<artifactId>shortcuts</artifactId>
<version>1.0.0</version>
<packaging>jar</packaging>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<maven.compiler.release>23</maven.compiler.release>
<appModule>shortcuts</appModule>
<appMainClass>shortcuts.Main</appMainClass>
<mavenCompilerPluginVersion>3.13.0</mavenCompilerPluginVersion>
<mavenJarPluginVersion>3.4.1</mavenJarPluginVersion>
<mavenDependencyPluginVersion>3.6.1</mavenDependencyPluginVersion>
<javaFxVersion>23</javaFxVersion>
</properties>
<dependencies>
<dependency>
<groupId>org.openjfx</groupId>
<artifactId>javafx-controls</artifactId>
<version>${javaFxVersion}</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>${mavenCompilerPluginVersion}</version>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<version>${mavenJarPluginVersion}</version>
<configuration>
<outputDirectory>target/jmods</outputDirectory>
<archive>
<manifestEntries>
<Main-Class>${appMainClass}</Main-Class>
</manifestEntries>
</archive>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<version>${mavenDependencyPluginVersion}</version>
<executions>
<execution>
<id>copy-dependencies</id>
<phase>package</phase>
<goals>
<goal>copy-dependencies</goal>
</goals>
<configuration>
<includeScope>compile</includeScope>
<includeScope>runtime</includeScope>
<outputDirectory>target/jmods</outputDirectory>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<executions>
<execution>
<goals>
<goal>exec</goal>
</goals>
</execution>
</executions>
<configuration>
<executable>java</executable>
<arguments>
<argument>--module-path</argument>
<modulepath/>
<argument>--module</argument>
<argument>shortcuts/shortcuts.Main</argument>
</arguments>
</configuration>
</plugin>
</plugins>
</build>
</project>
---------- END SOURCE ----------
CUSTOMER SUBMITTED WORKAROUND :
Workaround is to useevent filter instead of accelerators.
FREQUENCY : always
$ java -version
openjdk version "23" 2024-09-17
OpenJDK Runtime Environment (build 23+37-2369)
OpenJDK 64-Bit Server VM (build 23+37-2369, mixed mode, sharing)
$ uname -a
Linux bastion 6.1.100-un-def-alt1 #1 SMP PREEMPT_DYNAMIC Fri Aug 2 06:40:54 UTC 2024 x86_64 GNU/Linux
A DESCRIPTION OF THE PROBLEM :
Ctrl+keys are handled differently by Scene if TextField has focus.
Option1 : scene event filter handles all keys
Option2: scene accelerators skips some keys like in example shown
STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
1. Set JAVA_HOME and PATH to jdk-23
2, Build and Launch
mvn clean package exec:exec
3, Press buttons: Ctrl+], Ctrl+[, Ctrl+\
All keys are reflected in label content.
4. Comment Option 1 and uncomment Option 2.
Now Ctrl+\ does not work
EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
All accelerators are handled properly
ACTUAL -
Some accelerators are not handled.
---------- BEGIN SOURCE ----------
Full project: https://github.com/petr-panteleyev/bug_shortcuts
=== shortcuts/Main.java ===
package shortcuts;
import javafx.application.Application;
import javafx.application.Platform;
import javafx.scene.control.ButtonType;
import javafx.scene.control.Dialog;
import javafx.scene.control.Label;
import javafx.scene.control.TextField;
import javafx.scene.input.KeyCode;
import javafx.scene.input.KeyCodeCombination;
import javafx.scene.input.KeyEvent;
import javafx.scene.layout.VBox;
import javafx.stage.Stage;
import java.util.Map;
import static javafx.scene.input.KeyCombination.SHORTCUT_DOWN;
class MainDialog extends Dialog {
private final Label label = new Label();
private final TextField textField = new TextField();
public MainDialog() {
getDialogPane().setContent(new VBox(10, label, textField));
getDialogPane().getButtonTypes().add(ButtonType.CLOSE);
Map<KeyCodeCombination, Runnable> accelerators = Map.of(
new KeyCodeCombination(KeyCode.BACK_SLASH, SHORTCUT_DOWN), () -> label.setText("BACK_SLASH"),
new KeyCodeCombination(KeyCode.CLOSE_BRACKET, SHORTCUT_DOWN), () -> label.setText("CLOSE_BRACKET"),
new KeyCodeCombination(KeyCode.OPEN_BRACKET, SHORTCUT_DOWN), () -> label.setText("OPEN_BRACKET")
);
/* Option 1 */
getDialogPane().getScene().addEventFilter(KeyEvent.KEY_RELEASED, event -> {
for (var a : accelerators.entrySet()) {
if (a.getKey().match(event)) {
a.getValue().run();
event.consume();
}
}
});
/* Option 2 */
// getDialogPane().getScene().getAccelerators().putAll(accelerators);
Platform.runLater(textField::requestFocus);
}
}
public class Main extends Application {
@Override
public void start(Stage stage) throws Exception {
new MainDialog().showAndWait();
}
public static void main(String[] args){
launch(args);
}
}
=== module-info.java ===
open module shortcuts {
requires javafx.controls;
exports shortcuts;
}
=== pom.xml ===
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>bugreports</groupId>
<artifactId>shortcuts</artifactId>
<version>1.0.0</version>
<packaging>jar</packaging>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<maven.compiler.release>23</maven.compiler.release>
<appModule>shortcuts</appModule>
<appMainClass>shortcuts.Main</appMainClass>
<mavenCompilerPluginVersion>3.13.0</mavenCompilerPluginVersion>
<mavenJarPluginVersion>3.4.1</mavenJarPluginVersion>
<mavenDependencyPluginVersion>3.6.1</mavenDependencyPluginVersion>
<javaFxVersion>23</javaFxVersion>
</properties>
<dependencies>
<dependency>
<groupId>org.openjfx</groupId>
<artifactId>javafx-controls</artifactId>
<version>${javaFxVersion}</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>${mavenCompilerPluginVersion}</version>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<version>${mavenJarPluginVersion}</version>
<configuration>
<outputDirectory>target/jmods</outputDirectory>
<archive>
<manifestEntries>
<Main-Class>${appMainClass}</Main-Class>
</manifestEntries>
</archive>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<version>${mavenDependencyPluginVersion}</version>
<executions>
<execution>
<id>copy-dependencies</id>
<phase>package</phase>
<goals>
<goal>copy-dependencies</goal>
</goals>
<configuration>
<includeScope>compile</includeScope>
<includeScope>runtime</includeScope>
<outputDirectory>target/jmods</outputDirectory>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<executions>
<execution>
<goals>
<goal>exec</goal>
</goals>
</execution>
</executions>
<configuration>
<executable>java</executable>
<arguments>
<argument>--module-path</argument>
<modulepath/>
<argument>--module</argument>
<argument>shortcuts/shortcuts.Main</argument>
</arguments>
</configuration>
</plugin>
</plugins>
</build>
</project>
---------- END SOURCE ----------
CUSTOMER SUBMITTED WORKAROUND :
Workaround is to useevent filter instead of accelerators.
FREQUENCY : always