Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

JavaFX entirely customized windows?

I would like to have an application where I've entirely customized the window's appearance. So far I've learned that I can remove the typical window stuff with:

class Application extends javafx.application.Application {
  /**
   * Starts the application.
   *
   * @param stage
   */
  override def start(stage: Stage) {
    stage.initStyle(StageStyle.TRANSPARENT)

    // Load the main window view.
    val loader = new FXMLLoader()
    loader.setLocation(getClass.getResource("/com/myproj/application/MainWindow.fxml"))

    val root = loader.load().asInstanceOf[Parent]
    val scene: Scene = new Scene(root, Color.TRANSPARENT)

    stage.setScene(scene)
    stage.show()
  }
}

Everything else works fine, except that window dragging, double-click-to-maximize, dragging to screen top edge on Windows should active maximizing, etc. The native Window capabilities are missing entirely.

Can I somehow rather easily customize the entire appear of the window without losing all these nice capabilities.

I'm talking about something like Adobe Photoshop which looks entirely different but still retains these features (or implements them on top of their UI manually).

It would be a start if I could at least implement dragging + window buttons for starters. I am targeting Linux, Mac and Windows here.

like image 299
Tower Avatar asked Oct 13 '12 15:10

Tower


1 Answers

See the customized window appearance and handling in the Ensemble Sample application, which includes source code. Download the source, build it and run it as a standalone application rather than embedded in a browser. It isn't going to be exactly what you are asking for because stuff like dragging to screen top edge to activate maximizing isn't going to work I think, but it should be very close and you could always code something yourself which maximized the window when it was dragged near the top edge. The Ensemble window has features like custom resize decorations, minimize, maximize, close icons, an area at the top of the window you can use to drag the window around or double click to maximize or minimize the window - i.e. most of the standard features you would expect from a desktop windowing system.

To get something even closer to what you are asking, perhaps you could hack something together by creating two windows. One, a standard decorated stage window which includes screen borders, the other an undecorated or transparent child stage always displayed on top of the main window and overlaying the borders of the main window with a custom rendering. I think you may run into difficulties trying to implement this approach, so I wouldn't really recommend it.

You may like to try an UNDECORATED stage style rather than TRANSPARENT and see if you get better native Windows integration with that.

There are some open feature request currently scheduled for JavaFX to be shipped with JDK8, Windows: support Aero Glass effects for top-level windows, Mac: Support NSTexturedBackgroundWindowMask style for windows and The solid white background created in a Stage should be created - if needed - in the Scenegraph, which, when implemented, will likely help you to acheive your goal - vote for them, if such features are important to you.

Ensemble Sample Application

Also checkout VFXWindows which is an open source windowing framework for JavaFX.

Update

Also related is the Undecorator project which allows you to easily create a JavaFX stage with standard minimize/maximize/close/resize chrome controls that are rendered via the JavaFX engine rather than the OS windowing system. This allows you to achieve the kind of custom control over window rendering that an application like Ensemble displays.

like image 162
jewelsea Avatar answered Sep 18 '22 12:09

jewelsea