Why JavaFX application and scene builder is showing garbled text? - java

Here's how my scene builder looks like:
and here's the GUI:
The standalone scene builder:
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

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:
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

I have also encountered this problem and after reading many forums I think I have a possible explanation and solution. The problem seems to be related to Mac users and Segoe UI;
I am guessing that because the font is used in Microsoft products, Macs are unable to render the font, even downloaded versions have not worked.
The simplest fix, which has worked for me so far, is to include
style="-fx-font-family: serif"
in the root node or add it in the controller or add
.root{
-fx-font-family: serif
}
to your CSS. This works for any font in your system.

Installing Segoe UI was a huge red herring for me. Instead, I changed the version of javafx defined in build.gradle to 17.0.1 and upgraded JavaFX to 16

Related

OpenJFX / JavaFX 16 WebView cannot display a simple webpage using WebGL

I've just tried to run a rudimentary example using OpenJFX 16 that is intended to open a webpage of a WebGL demo showing some blobs:
import javafx.application.Application;
import javafx.scene.Scene;
import javafx.scene.layout.VBox;
import javafx.scene.web.WebView;
import javafx.stage.Stage;
public class Main extends Application {
public static void main(final String[] args) {
launch(args);
}
#Override
public void start(final Stage primaryStage) {
primaryStage.setTitle("JavaFX WebView Example");
WebView webView = new WebView();
webView.getEngine().load("https://webglsamples.org/blob/blob.html");
VBox vBox = new VBox(webView);
Scene scene = new Scene(vBox, 960, 600);
primaryStage.setScene(scene);
primaryStage.show();
}
}
However, I get the following error message:
This page requires a browser that supports WebGL. Click here to
upgrade your browser.
I use Adoptium OpenJDK 16 under Mageia Linux. Is it the expected behaviour? I'm disappointed because a member of Gluon's support team told me:
there are some WebGL demos that run just fine in the WebView component
What can I do to solve this problem? Is it expected to work only with OpenJFX 17?
Edit.: Someone else tried with OpenJFX 18, it still doesn't work:
https://jvm-gaming.org/t/openjfx-javafx-webview-not-working-with-webgl/70495/2
JavaFXs WebView does not support WebGL and I am not aware of any plans to change that. Who told you that there are working demos for that and where can they be found? There have only been some experiments to resolve this issue but no official solution yet. E.g., https://github.com/miho/NativeFX

InteliJ JavaFX displaying blank white screen when booting

I'm trying to get a starter project for a template running over for JavaFX, the assignment is to get a hello world program up and running using JavaFX to get the program running.
(Some Background context: We're using IntelliJ for our class assignment, but recently we found out that it seems(?) support for JavaFx has been discontinued within InteliJ, regardless the same assignment remains so we installed a third party library following the steps over from a guide about getting the library, ( How to get JavaFX and Java 11 working in IntelliJ IDEA ), the instructions helped to get the program running and compiled and I used the paths out, but when I ran the program, I got a blank white screen, and I have no clue if this is normal or not.)
The code is just the default JavaFX template from Intllij, I've tried installing the SDKS and JDKS (which seemed to help the program compile), but when running, I just get a blank white screen.
Here is a screenshot of the white screen problem https://i.imgur.com/7ZYju3M.jpg
And the code below; it's just a IntelliJ default startup, but I don't know why it doesn't work.
package sample;
// Original Imports found in testTemplate
import javafx.application.Application;
import javafx.fxml.FXMLLoader;
import javafx.scene.Parent;
import javafx.scene.Scene;
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"));
primaryStage.setTitle("Hello World");
primaryStage.setScene(new Scene(root, 300, 275));
primaryStage.show();
}
public static void main(String[] args) {
launch(args);
}
}
package sample;
public class Controller {
}
We expected the results to say hello world. I think so anyways, but I actually have no clue what it's supposed to look like as it's my first time, I think it's supposed to say hello world. (Later on, we're supposed to get the GUI configured, but for right now, I just want to figure out what's going wrong with the program.)

(Linux) Allow JavaFX AlwaysOnTop Window to bypass the x11 window manager

I recently asked a similar question about this for OSX and found a solution using the com.sun.glass package. However, this solution does not seem to work on X11-based desktop environments.
The issue:
I am trying to write a borderless window overlay that can be placed above ALL other desktop components, including the dock and menubar of any given Linux desktop environment which uses x11. Currently, when I use AlwaysOnTop(true) with my JavaFX window, the window is placed above all other windows but is NOT placed above the window managers UI (taskbar) due to it having a higher window level. The screenshot below shows what happens when using AlwaysOnTop: the entirety of the vertical white window should be placed above the taskbar but is instead forced below it. See screenshot:
There is a solution for this issue with Qt through using the x11bypasswindowmanager window flag, so I figured it must be possible through Java!
The only current solution I have is to use wmctrl directly through the commandline using a subprocess. This is not really suitable, as a lot of linux systems to not come with wmctrl installed.
Below is the code snippet I am using to generate the window in the above screenshot:
import javafx.application.Application;
import javafx.scene.Scene;
import javafx.scene.layout.StackPane;
import javafx.stage.Stage;
import javafx.stage.StageStyle;
public class Main extends Application {
public static void main(String[] args) {
launch(args);
}
#Override
public void start(Stage primaryStage) {
primaryStage.setTitle("Hello World!");
StackPane root = new StackPane();
primaryStage.setScene(new Scene(root, 200, 3000));
primaryStage.setAlwaysOnTop(true);
primaryStage.initStyle(StageStyle.UNDECORATED);
primaryStage.setX(800);
primaryStage.setY(0);
primaryStage.show();
}
}

java component not visible in windows 8 and 10 or its variant due to corrupted graphics driver

I tested my application based on java(javafx) in various version of windows(7,8,10) and it worked perfectly but when i tried to run it my client machine(Windows-10 Home(freshly installed)), it is getting run but the internal component of it is not visible, only thing what i can see is border, minimize,maximize and close button.
For the sake of convenience, attached here
are the results of simple java program or output which I got in my machine and client's machine respectively:
However when i made the same version of jar using Swing...it worked.
Note: Required version of JRE is there in system.
Follwing is the source code:::
the code is simple:::
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package hello;
import javafx.application.Application;
import javafx.event.ActionEvent;
import javafx.event.EventHandler;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.layout.StackPane;
import javafx.stage.Stage;
/**
*
* #author oa
*/
public class Hello extends Application {
#Override
public void start(Stage primaryStage) {
Button btn = new Button();
btn.setText("Say 'Hello World'");
btn.setOnAction(new EventHandler<ActionEvent>() {
#Override
public void handle(ActionEvent event) {
System.out.println("Hello World!");
}
});
StackPane root = new StackPane();
root.getChildren().add(btn);
Scene scene = new Scene(root, 300, 250);
primaryStage.setTitle("Hello World!");
primaryStage.setScene(scene);
primaryStage.show();
}
/**
* #param args the command line arguments
*/
public static void main(String[] args) {
launch(args);
}
}
Note: I can smell the conflicts between javafx and windows-10 version
Finally got a solution, after an hour of work out... As javafx rely on the graphic card installed on the system..
For JavaFX applications to take advantage of the new hardware acceleration pipeline provided by JavaFX, your system must feature one of a wide range of GPUs currently available in the market. If your system does not support hardware acceleration, then JavaFX uses the Java2D software pipeline.
so one has to ensure that its working properly. In any case if its corrupted or not working properly then javafx doesnt give you the desired result. So in any case if you found that your graphics card is not working properly then just disable it(graphics card)... the javafx will give the desired result thereafter. So basically it was not an WINDOWS 10 and javafx problem...it was graphic related issues

Is WebView "embeddable" in TextFlow?

It says on the OpenJDK samples for TextFlow that it can have arbitrary Nodes as children, e.g. Button. I was wondering if WebView can be a possible child? If so, then I must be doing something wrong. When I add it to the TextFlow, the WebView just takes up space, but displays nothing. The content I've tried range from simple HTML pages, up to videos from services like YouTube.
Since this control is fairly new, I was unable to find an existing use case online.
In case you're wondering why I want this. I have a ListView that displays rich content. If TextFlow is capable of displaying any Node, then it would save me from creating multiple extension classes for the different types I want to display on the ListView (e.g. Video, formatted text, HTML - these I already did, and they work fine), and I can manage content easily by just managing the TextFlow's children.
Thanks.
Yes, you can. Note that the web view will be layout out using its baselineOffset, which is not going to be appropriate for use in a TextFlow (I think what happens is it's bottom edge will be aligned with the bottom edge of the text, and it gets clipped to the height of the text row.) You can get around this by wrapping it in a Group:
import javafx.application.Application;
import javafx.scene.Group;
import javafx.scene.Scene;
import javafx.scene.text.Text;
import javafx.scene.text.TextFlow;
import javafx.scene.web.WebView;
import javafx.stage.Stage;
public class WebViewInTextFlow extends Application {
#Override
public void start(Stage primaryStage) {
TextFlow flow = new TextFlow();
WebView webView = new WebView();
webView.getEngine().getLoadWorker().stateProperty().addListener((obs, oldState, newState) -> System.out.println(newState));
webView.getEngine().load("http://stackoverflow.com/questions/31353921/is-webview-embeddable-in-textflow/31357609#31357609");
flow.getChildren().addAll(new Text("Some text"), new Group(webView), new Text("Some more text"));
primaryStage.setScene(new Scene(flow, 800, 800));
primaryStage.show();
}
public static void main(String[] args) {
launch(args);
}
}

Categories