I was trying to learn javafx. In my application, I decided to check a few things so I decided that you could exit fullscreen only when you typed "abcd". But I can't get it work. I've tried all possible combinations but still can't exit the fullscreen.
package org.example.first;
import javafx.application.Application;
import javafx.scene.Group;
import javafx.scene.Scene;
import javafx.scene.image.Image;
import javafx.scene.input.KeyCombination;
import javafx.scene.paint.Color;
import javafx.stage.Stage;
import java.io.IOException;
public class HelloApplication extends Application {
@Override
public void start(Stage stage) throws IOException {
Group root = new Group();
Scene scene = new Scene(root, Color.BLACK);
Image icon = new Image("file.png");
stage.setTitle("MyApplication");
stage.setScene(scene);
stage.getIcons().add(icon);
stage.setFullScreen(true);
stage.setFullScreenExitHint("To exit fullscreen, write abcd");
stage.setFullScreenExitKeyCombination(KeyCombination.valueOf("abcd"));
stage.show();
}
public static void main(String[] args) {
launch();
}
}
This is the code I've written. I've tried to get it to work but I don't know what's wrong with it. JavaFX 17 and Java 18
This is not possible with a key combination like "abcd".
From the documentation of KeyCombination
:
A key combination consists of a main key and a set of modifier keys. The main key can be specified by its key code - KeyCodeCombination or key character - KeyCharacterCombination. A modifier key is shift, control, alt, meta or shortcut and can be defined as DOWN, UP or ANY.
"a", "b", "c" and "d" are all main keys which violates that a main key restriction.