JavaFX 完全定制的窗口? [英] JavaFX entirely customized windows?

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

问题描述

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

class Application 扩展 javafx.application.Application {/*** 启动应用程序.** @param 阶段*/覆盖定义开始(阶段:阶段){stage.initStyle(StageStyle.TRANSPARENT)//加载主窗口视图.val 加载器 = 新 FXMLLoader()loader.setLocation(getClass.getResource("/com/myproj/application/MainWindow.fxml"))val root = loader.load().asInstanceOf[Parent]val 场景:Scene = new Scene(root, Color.TRANSPARENT)stage.setScene(场景)舞台表演()}}

其他一切正常,除了窗口拖动、双击最大化、拖动到 Windows 上的屏幕顶部边缘应激活最大化等.原生窗口功能完全缺失.

我能否以某种方式轻松自定义窗口的整个外观,而不会失去所有这些不错的功能.

我说的是 Adob​​e Photoshop 之类的东西,它看起来完全不同,但仍保留了这些功能(或手动在其 UI 之上实现它们).

如果我至少可以为初学者实现拖动 + 窗口按钮,那将是一个开始.我的目标是 Linux、Mac 和 Windows.

解决方案

在 ,这是一个用于 JavaFX 的开源窗口框架.

更新

同样相关的是 Undecorator 项目,它允许您使用标准的最小化/最大化/关闭/调整镶边控件轻松创建 JavaFX 阶段,这些控件通过 JavaFX 引擎而不是操作系统窗口系统呈现.这允许您实现对像 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 完全定制的窗口?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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