JavaFX: Undecorated Window

Dorothy picture Dorothy · Nov 14, 2011 · Viewed 43.2k times · Source

I am attempting to make a Windows PC Toast notification. Right now I am using a mixture of Swing and JavaFX because I did not find a way to make an undecorated window with FX. I would much prefer to only use JavaFX.

So, how can I make an undecorated window?

Edit: I have discovered that you can create a stage directly with new Stage(StageStyle.UNDECORATED).

Now all I need to know is how to initialize the toolkit so I can call my start(Stage stage) method in MyApplication. (which extends Application)

I usually call Application.launch(MyApplication.class, null), however that shields me from the creation of the Stage and initialization of the Toolkit.

So how can I do these things to allow me to use start(new Stage(StageStyle.UNDECORATED)) directly?

Answer

pmoule picture pmoule · Nov 15, 2011

I don't get your motivation for preliminary calling the start()-method setting a stage as undecorated, but the following piece of code should do what you want to achieve.

package decorationtest;

import javafx.application.Application;
import javafx.stage.StageStyle;
import javafx.scene.Group;
import javafx.scene.Scene;
import javafx.stage.Stage;

public class DecorationTest extends Application {

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

    @Override
    public void start(Stage primaryStage) {
        primaryStage.initStyle(StageStyle.UNDECORATED);

        Group root = new Group();
        Scene scene = new Scene(root, 100, 100);

        primaryStage.setScene(scene);
        primaryStage.show();
    }
}