32

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?

Dorothy
  • 2,842
  • 10
  • 33
  • 46

1 Answers1

56

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();
    }
}
Michael Berry
  • 70,193
  • 21
  • 157
  • 216
pmoule
  • 4,322
  • 2
  • 34
  • 39
  • 1
    Well it makes an undecorated frame but it also ads it to the task bar. I guess what I want is a parent-less popup? – Dorothy Nov 15 '11 at 20:01
  • 2
    This doesn't seem to work without mixing with Swing. A solution could be to make a Swing-based wrapper application for the tray icon. – pmoule Nov 15 '11 at 22:28
  • 7
    @Dorothy This is really old, but for sake of future visitors, calling `initOwner()` on the `Stage` and passing a reference to your main stage will prevent the notification's stage from being added to the task bar. – Cypher Jan 27 '16 at 22:32