JavaFX辅助屏幕“始终在顶部”所有应用程序 [英] JavaFX Secondary Screen "Always on Top" of All Applications

查看:288
本文介绍了JavaFX辅助屏幕“始终在顶部”所有应用程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经阅读过使用JDialog来包装JFXPanel以使用JDialog的alwaysOnTop方法。它有效,但我遇到了这个黑客的一个小问题。



因为我正在使用这种技术为我的主应用程序(弹出窗口等)创建辅助窗口,我需要将它们设置在主窗口的顶部。如果我使用包装器hack来执行此操作,则顶部面板始终位于所有(包括其他应用程序)的顶部。



有没有办法将辅助屏幕仅放在我的应用程序之上?我不喜欢可以在我的应用程序的主窗口和辅助窗口之间拖动另一个应用程序。

解决方案

我建议不要使用 JDialog JFXPanel ,但仅使用JavaFX 阶段



让您的辅助屏幕为 Stage 并调用 secondaryStage.initOwner(primaryStage)在您显示第二阶段之前。



来自舞台文档:


舞台可以选择拥有一个所有者窗口。当窗口是舞台的所有者时,它被称为该舞台的父级。 。 。舞台将始终位于其父窗口的顶部。


我认为设置辅助阶段的所有者,正确地满足了仅在我的应用程序之上的辅助屏幕的要求。 / p>




更新:回答评论中的其他问题


我不希望在辅助节点打开后与主舞台进行任何交互(必须关闭辅助窗口才能再次进行交互)。


要阻止对主要阶段的输入,在显示第二阶段之前,请致电: secondaryStage.initModality(Modality.WINDOW_MODAL)



你可以使用 APPLICATION_MODAL 代替 WINDOW_MODAL 如果您希望阻止对任何其他应用程序窗口的所有输入 - 使用哪一个取决于您想要的用户体验。


在api中没有任何明显的东西可以将辅助屏幕置于主屏幕中心。无论主屏幕在哪里,它总是以显示器为中心。


这部分问题是舞台的中心位置。副本的答案有用于执行子窗口居中的示例代码。



这是正确的,公共api中没有任何内容围绕父窗口定位子窗口。我已经提交了此功能的功能请求添加辅助方法以相对于节点定位弹出窗口,但是从JavaFX 2.2开始还没有实现功能请求。



有一个示例项目我创建了相对定位的子对话框,这可能很有用。



只是为了在父节点中居中,最好在显示子节目之前查询舞台位置和宽度,然后在显示时适当地设置子节点的x和y坐标。所有这一切都可以基于 x y width 属性。



JavaFX UI控制沙箱,它可能提供您需要的一些功能,因此您无需自己编写代码。



及时全部您要求的功能可能最终会出现在JavaFX核心平台中,但我认为JavaFX 2.2还没有完全实现。


I've read about using a JDialog to wrap a JFXPanel in order to use JDialog's alwaysOnTop method. It works, but I'm having a small issue with this hack.

Since I'm using this technique to make secondary windows to my main application (popups etc), I need to set them on top of the main window. If I use the wrapper hack to do this, the top panel is "always on top" of everything (including other applications).

Is there a way to put the secondary screen only on top of my application? I don't like the fact that another application can be dragged in between the main window and secondary window of my application.

解决方案

I suggest not using JDialog and JFXPanel, but only using JavaFX Stages.

Make your secondary screen a Stage and invoke secondaryStage.initOwner(primaryStage) before you show the secondary stage.

From the Stage documentation:

A stage can optionally have an owner Window. When a window is a stage's owner, it is said to be the parent of that stage . . . A stage will always be on top of its parent window.

I believe setting the owner of the secondary stage, correctly fulfills your requirement of "secondary screen only on top of my application".


Update: answers to additional questions from comments

I don't want there to be any interaction with the main stage once the secondary is open (the secondary window must be closed to allow interaction again).

To block input to the primary stage, Before showing the secondary stage, call: secondaryStage.initModality(Modality.WINDOW_MODAL).

You could use APPLICATION_MODAL instead of WINDOW_MODAL if you preferred to block all input to any other of your application windows - which one to use depends on the user experience you want.

There's nothing obvious in the api that would center the secondary screen on the main screen. It just always centers on the monitor, no matter where the main screen is.

This part of the question is a duplicate of Center location of stage. The answer to the duplicate has sample code for performing the centering of the child window.

That's right, there is nothing in the public api around positioning child windows relative to parent windows. I've filed a feature request for this functionality Add helper methods for positioning popups relative to nodes, but the feature request has not yet been implemented as of JavaFX 2.2.

There is a sample project I created to do relative positioning of child dialogs, which might be useful.

Just for centering within the parent, you are probably best off querying the stage location and width before displaying the child and then setting the x and y co-ordinates of the child appropriately when you display it. All of this can be done based on x, y and width properties of windows.

There is also a dialog project in the JavaFX UI controls sandbox which might provides some of the functionality you require so that you don't need to code it yourself.

In time all of the functionality you are requesting will probably end up in the JavaFX core platform, but I don't think it's all quite there yet for JavaFX 2.2.

这篇关于JavaFX辅助屏幕“始终在顶部”所有应用程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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