admin管理员组

文章数量:1134248

I'm using java 21.0.5, JavaFX version 20.0.2. My problem is that running the below code

import javafx.collections.*;
import javafx.geometry.*;
import javafx.scene.control.*;
import javafx.scene.image.Image;
import javafx.scene.layout.*;
import javafx.scene.paint.Color;
import javafx.scene.text.Text;
import javafx.stage.*;
import javafx.scene.*;
import javafx.application.Application;
import javafx.application.Platform;

public class MyApplication extends Application {

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

    @Override
    public void start(Stage primaryStage) {
        VBox root = new VBox();
        root.getChildren().add(new Label("test"));
        root.setStyle("-fx-background-color:transparent;");
        Scene scene = new Scene(root, 800, 600);

        primaryStage.setTitle("Cursor Control");
        scene.setFill(Color.TRANSPARENT);
        //primaryStage.initStyle(StageStyle.UNIFIED);
        scene.setFill(Color.TRANSPARENT);
        primaryStage.resizableProperty().setValue(Boolean.FALSE);
        primaryStage.setScene(scene);
        primaryStage.show();
    }
}

The window does unify, however removing focus from it in any way, for example clicking off, causes the entire unified window to turn pure white. When commenting out the single initStyle, while the stage is still white as expected, the test text is visible, whereas said text and any more content within the main window disappears upon defocusing when the unified stage style is selected/uncommented.

Images attached are screenshots of the unified and non-unified windows focused/defocused:

Unified Style

Focused:

Unfocused:

Normal Style (not unified)

Focused:

Unfocused:


Hopefully there is a way for a unified window to not exhibit this behaviour, I would greatly appreciate it if there is a solution. This is the main code I'm working with to try and sort the issue before expanding it, and no errors are produced in the console.

本文标签: javaHow can I prevent a unified JavaFX window from turning allwhite on defocusStack Overflow