Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to make a JavaFX-Widget

is it possible to stick a stage to the desktop?

I want to behave my application as widget, so when it starts it should be displayed right above the desktop and not in front of the current application which might be opened.

The other condition for a widget would be that it has no entry in the taskbar. Is that also possible?

like image 376
Gundon Avatar asked Mar 29 '13 17:03

Gundon


People also ask

Is JavaFX used for GUI?

Introduction to JavaFX GUI. In Java, JavaFX is considered a Graphical User Interface (GUI) toolkit that helps create desktop applications and games.

Can JavaFX be used for desktop applications?

JavaFX is an open source, next generation client application platform for desktop, mobile and embedded systems built with Java. It is offered as a cross-platform Java library and it delivers consistent graphical user interfaces across a wide range of operating systems and devices.

What can I build with JavaFX?

JavaFX is a set of graphics and media packages that enables developers to design, create, test, debug, and deploy rich client applications that operate consistently across diverse platforms.


1 Answers

I tried this with JavaFX 2.2 and had the following results:

so when it starts it should be displayed right above the desktop and not in front of the current application which might be opened

Calling stage.toBack will place a stage behind any other windows.

I was able to get a window to always stay behind other windows most of the time (at least on a mac). To do this, I added a couple of listeners and filters before showing the stage in a clock application.

stage.focusedProperty().addListener(new ChangeListener<Boolean>() {
  @Override
  public void changed(ObservableValue<? extends Boolean> observableValue, Boolean wasFocused, Boolean focused) {
    stage.toBack();
  }
});

stage.addEventFilter(MouseEvent.ANY, new EventHandler<MouseEvent>() {
  @Override
  public void handle(MouseEvent mouseEvent) {
    stage.toBack();
  }
});

There is an existing request for an ability to set a stage to always be on top. You could create a new corresponding request for an ability for a stage to always be behind.

The other condition for a widget would be that it has no entry in the taskbar

On Windows, I think if you init the stage style to StageStyle.UTILITY, then Windows does not show an icon for the stage in the Windows taskbar.

I tried a couple of different stage styles on OS X and a little Java cup icon would always show in the OS X dock when I ran the app and (unlike windows) setting the icons for the stage did not get rid of the Java cup icon. Perhaps if you created a self-contained OS X application you could turn the icon off for it during the packaging step, or set the icon to a transparent image so that it would not be visible to the user.

You could also create a feature request for this (separate from the always to back one) in the JavaFX issue tracker. If you create any issues related to this, explain your use case and link back to this question.

like image 170
jewelsea Avatar answered Oct 17 '22 00:10

jewelsea