问题描述
我已经阅读过使用JDialog来包装JFXPanel以使用JDialog的alwaysOnTop方法。它有效,但我遇到了这个黑客的一个小问题。
因为我正在使用这种技术为我的主应用程序(弹出窗口等)创建辅助窗口,我需要将它们设置在主窗口的顶部。如果我使用包装器hack来执行此操作,则顶部面板始终位于所有(包括其他应用程序)的顶部。
有没有办法将辅助屏幕仅放在我的应用程序之上?我不喜欢可以在我的应用程序的主窗口和辅助窗口之间拖动另一个应用程序。
我建议不要使用和,但仅使用JavaFX 。
让您的辅助屏幕为 Stage
并调用在您显示第二阶段之前。
来自舞台文档:
我认为设置辅助阶段的所有者,正确地满足了仅在我的应用程序之上的辅助屏幕的要求。 / p>
更新:回答评论中的其他问题
要阻止对主要阶段的输入,在显示第二阶段之前,请致电:。
你可以使用代替如果您希望阻止对任何其他应用程序窗口的所有输入 - 使用哪一个取决于您想要的用户体验。
这部分问题是舞台的中心位置。副本的答案有用于执行子窗口居中的示例代码。
这是正确的,公共api中没有任何内容围绕父窗口定位子窗口。我已经提交了此功能的功能请求,但是从JavaFX 2.2开始还没有实现功能请求。
有一个我创建了相对定位的子对话框,这可能很有用。
只是为了在父节点中居中,最好在显示子节目之前查询舞台位置和宽度,然后在显示时适当地设置子节点的x和y坐标。所有这一切都可以基于和属性。
,它可能提供您需要的一些功能,因此您无需自己编写代码。
及时全部您要求的功能可能最终会出现在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:
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
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.
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辅助屏幕“始终在顶部”所有应用程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!