Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why JavaFX application and scene builder is showing garbled text?

Here's how my scene builder looks like:

enter image description here

and here's the GUI:

enter image description here

The standalone scene builder:

enter image description here

I just run the following source code from Java SDK demos:

package sample;

import javafx.application.Application;
import javafx.event.ActionEvent;
import javafx.event.EventHandler;
import javafx.fxml.FXMLLoader;
import javafx.scene.control.Button;
import javafx.scene.Parent;
import javafx.scene.Scene;
import javafx.scene.layout.StackPane;
import javafx.stage.Stage;
import javafx.stage.Stage;

public class Main extends Application {

    @Override
    public void start(Stage primaryStage) throws Exception{
        Parent root = FXMLLoader.load(getClass().getResource("sample.fxml"));
        Button btn = new Button();
        btn.setText("Say 'Hello World'!");
        StackPane root_ctn = new StackPane();
        root_ctn.getChildren().add(btn);
        btn.setOnAction(new EventHandler<ActionEvent>() {
            @Override
            public void handle(ActionEvent actionEvent) {
                System.out.println("Hello World!");
            }
        });
        primaryStage.setTitle("Hello World");
        primaryStage.setScene(new Scene(root_ctn, 300, 275));
        primaryStage.show();
    }


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

The only place the text looks good is in the console.

View idea.log

like image 968
Steve Avatar asked Mar 22 '21 13:03

Steve


People also ask

How do I fix JavaFX error?

If this is your case also, you can do fix this by simply right-clicking on the javaFX project folder-> Build Path-> Configure Build Path-> Select JavaFX SDK-> Remove library-> Select classpath -> add library-> user library-> select library-> apply.

How do you refresh a scene in JavaFX?

The JavaFX scene can be forcibly refreshed by changing the width or height of the Scene by a fractional number of pixels (for example, 0.001). This change forces the background windowing and rendering services to recalculate layout and rendering requirements for the scene graph.

What is Scene Builder in JavaFX?

JavaFX Scene Builder is a visual layout tool that lets users quickly design JavaFX application user interfaces, without coding. Users can drag and drop UI components to a work area, modify their properties, apply style sheets, and the FXML code for the layout that they are creating is automatically generated in the background.

How do I open a FXML file in Scene Builder?

IntelliJ IDEA allows you to open .fxml files in JavaFX Scene Builder right from the IDE after you specify the path to the Scene Builder application in the settings. Download and install the latest version of Scene Builder.

How do I enable JavaFX in IntelliJ?

Configure JavaFX Scene Builder in IntelliJ IDEA. Download and install the latest version of Scene Builder. In the Settings/Preferences dialog Ctrl+Alt+S, select Languages and Frameworks | JavaFX. Click in the Path to SceneBuilder field. In the dialog that opens, select the Scene Builder application (executable file) on your computer and click OK.

How do I open a FXML file in IntelliJ?

IntelliJ IDEA allows you to open .fxml files in JavaFX Scene Builder right from the IDE after you specify the path to the Scene Builder application in the settings. Download and install the latest version of Scene Builder. In the Settings/Preferences dialog Ctrl+Alt+S, select Languages and Frameworks | JavaFX.


Video Answer


1 Answers

I did not yet find out the solution, but I found an interesting pattern: On your Gluon Scene Builder screenshot, there is written Pgy Rtqlgev, where it should be New Project, and Qrgp Rtqlgev where it should be Open Project. Note that every letter is substituted by the after next letter in the alphabet!

The same applies to Say 'Hello World'!, which is "translated" to Lc{ 'Jgrrq Yqtrf'!. Note that the letter y is replaced by a {, which comes two positions after y in the ASCII table. Interestingly, the characters ' and ! stay the same..

The space each letter takes is still the space of the correct letter, as you can see in the following graphic with the correct text on the green background: enter image description here

Update: Is it possible that the font "Segoe UI" is missing or flawed on your system? Can you use that font for example in Word?

Update: I found two other questions of users facing the same problem. In both cases the problem seems to be related to the Segoe UI font:

Scene Builder Editor displaying weird characters

JavaFX Scene builder shows wired characters

like image 136
user7291698 Avatar answered Oct 24 '22 10:10

user7291698