I am a beginner with the raspberry pi and trying to get my hands dirty on RPi 3b+, OS- Buster, 7 inch HDMI- touch screen.
I am trying to build simple gui with one button and one label to display a message. I am using JavaFX 11 with Intellij Idea as IDE. It is expected to display the message "Wow, this works!!!" in a label when "Show" button is touched. (as it works on any touch-enabled device like android phone or tab). Please find simple java source code for your reference. Note that code works perfect on mouse (click) events, but not for touch events. Please guide me if any of you have any experience with this. Any inputs or correct method to achieve this is appreciated. Thanks.
public class Main extends Application {
Button showButton;
Label label;
@Override
public void start(Stage primaryStage) throws Exception{
String appTitle = "JavaFx Touch Demo App";
String labelShowTextMsg = "Wow, this works!!!";
primaryStage.setTitle(appTitle);
label = new Label();
label.setText("");
label.setTranslateY(-50);
showButton = new Button();
showButton.setText("Show");
showButton.setOnTouchReleased(e -> label.setText(labelShowTextMsg));
StackPane layout = new StackPane();
layout.getChildren().addAll(showButton, label);
primaryStage.setScene(new Scene(layout, 300, 275));
primaryStage.show();
}
public static void main(String[] args) {
launch(args);
}
}