Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

JavaFX: can you create a stage that doesn't show on the task bar and is undecorated?

Tags:

javafx-8

I'm trying to create a stage that doesn't appear on the Windows task bar and is undecorated (no borders and no close/minimize/maximize buttons). My end goal is to create a tray icon application that will pop up notification windows.

It's similar to this question where I want the behavior of both StageStyle.UTILITY (which prevents the stage from showing on the task bar) and StageStyle.TRANSPARENT (which is a completely undecorated window).

The referenced question doesn't work for me because I don't have a parent stage from which to make a modal window. Any ideas on how to get this to work? Thanks

like image 302
dejuknow Avatar asked Jul 03 '14 22:07

dejuknow


People also ask

Can you have multiple stages displayed in a JavaFX program?

You can have multiple stages displayed in a JavaFX program.

How is the stage created in JavaFX?

The JavaFX Stage class is the top level JavaFX container. The primary Stage is constructed by the platform. Additional Stage objects may be constructed by the application. Stage objects must be constructed and modified on the JavaFX Application Thread.

What method is invoked to display a stage in JavaFX?

Showing a Stage The difference between the JavaFX Stage methods show() and showAndWait() is, that show() makes the Stage visible and the exits the show() method immediately, whereas the showAndWait() shows the Stage object and then blocks (stays inside the showAndWait() method) until the Stage is closed.


Video Answer


1 Answers

I was able to workaround this issue with the following code:

    Stage stage = new Stage();

    stage.initStyle(StageStyle.UTILITY);
    stage.setMaxHeight(0);
    stage.setMaxWidth(0);
    stage.setX(Double.MAX_VALUE);

StageStyle.UTILITY will avoid creating a taskbar icon. I set the width and height to 0 make the window small and then use stage.setX(Double.MAX_VALUE) to place it far off screen so it doesn't show up. It's a bit hokey, but it seems to work fine.

like image 81
dejuknow Avatar answered Oct 07 '22 14:10

dejuknow