JavaFX完全自定义windows? [英] JavaFX entirely customized windows?

查看:501
本文介绍了JavaFX完全自定义windows?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想有一个应用程序,我完全自定义窗口的外观。到目前为止,我已经了解到我可以删除典型的窗口内容:

  class应用程序扩展javafx.application.Application {
/ **
*启动申请。
*
* @param stage
* /
覆盖def start(阶段:Stage){
stage.initStyle(StageStyle.TRANSPARENT)

//加载主窗口视图。
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()
}
}

其他一切正常,除了窗口拖动,双点击最大化,在Windows上拖动到屏幕上边缘应该激活最大化等等。本机窗口功能完全缺失。



我可以以某种方式轻松地自定义整个在没有失去所有这些优秀功能的情况下出现在窗口中。



我说的是像Adobe Photoshop这样看起来完全不同但仍然保留这些功能的东西(或者在顶部实现它们)他们的UI手动)。



如果我至少可以为初学者实现拖动+窗口按钮,那将是一个开始。我在这里针对Linux,Mac和Windows。

解决方案

在,它是JavaFX的开源窗口框架。



更新



另外相关的是 Undecorator 项目,允许您轻松创建具有标准最小化/最大化/关闭/调整大小铬的JavaFX阶段通过JavaFX引擎而不是OS窗口系统呈现的控件。这允许您实现对Ensemble等应用程序显示的窗口渲染的自定义控制。


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.

解决方案

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.

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.

这篇关于JavaFX完全自定义windows?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆