scala JavaFX 完全定制的窗口?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/12874664/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
JavaFX entirely customized windows?
提问by Tower
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.
其他一切正常,除了窗口拖动、双击最大化、拖动到 Windows 上的屏幕顶部边缘应激活最大化等。原生窗口功能完全缺失。
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).
我说的是 Adobe Photoshop 之类的东西,它看起来完全不同,但仍保留了这些功能(或手动在其 UI 之上实现它们)。
It would be a start if I could at least implement dragging + window buttons for starters. I am targeting Linux, Mac and Windows here.
如果我至少可以为初学者实现拖动 + 窗口按钮,那将是一个开始。我的目标是 Linux、Mac 和 Windows。
采纳答案by jewelsea
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.
请参阅包含源代码的Ensemble 示例应用程序中的自定义窗口外观和处理。下载源,构建它并将其作为独立应用程序运行,而不是嵌入到浏览器中。它不会完全符合您的要求,因为诸如拖动到屏幕顶部边缘以激活最大化之类的东西我认为是行不通的,但它应该非常接近,您始终可以自己编写一些最大化窗口的代码当它被拖到顶部边缘附近时。Ensemble 窗口具有自定义调整大小装饰、最小化、最大化、关闭图标等功能,窗口顶部的区域可用于拖动窗口或双击以最大化或最小化窗口 - 即大多数标准功能您期望从桌面窗口系统。
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.
您可能想尝试 UNDECORATED 舞台风格而不是 TRANSPARENT ,看看是否能获得更好的原生 Windows 集成。
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 windowsand 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.
目前有一些开放的功能请求 JavaFX 与 JDK8 一起发布,Windows:支持顶级窗口的 Aero Glass 效果,Mac:支持 Windows 的 NSTexturedBackgroundWindowMask 样式和应该创建在舞台中创建的纯白色背景 - 如果需要- 在 Scenegraph 中,实施后可能会帮助您实现目标 - 如果这些功能对您很重要,请为他们投票。


Also checkout VFXWindowswhich is an open source windowing framework for JavaFX.
还可以查看 VFXWindows,它是 JavaFX 的开源窗口框架。
Update
更新
Also related is the Undecoratorproject 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.
还相关的是Undecorator项目,它允许您轻松创建一个 JavaFX 阶段,其中包含通过 JavaFX 引擎而不是操作系统窗口系统呈现的标准最小化/最大化/关闭/调整镶边控件。这允许您实现对像 Ensemble 这样的应用程序显示的窗口渲染的自定义控制。
回答by Oshan_Mendis
You can use thislibrary. It is a fully customizable JavaFx Stage (CustomStage). You can see in-detail description of how to use it in this CustomStage Wiki
你可以使用这个库。它是一个完全可定制的 JavaFx 舞台(CustomStage)。您可以在此CustomStage Wiki 中查看有关如何使用它的详细说明
It has,
它有,
- Window resizing
- Default action buttons and their behaviour (close, maximize/restore, minimize)
- Window dragging
- Window is automatically scaled as for screen resolution
- Very responsive
- Stylable (via css and methods)
- Can achieve transparency
- Has in-built navigation panes and drawers
- etc.
- 窗口大小调整
- 默认操作按钮及其行为(关闭、最大化/恢复、最小化)
- 窗口拖动
- 窗口根据屏幕分辨率自动缩放
- 非常敏感
- 风格化(通过 css 和方法)
- 可以实现透明
- 具有内置导航窗格和抽屉
- 等等。

