[英]Closing a nested modal window, without the “blurp” sound
I have 3 windows... 我有3个窗户...
main
: main application, main
:主要应用程序
mod-win1
: a modal window opened from main
, to edit/create certain objects, mod-win1
:从main
打开的模式窗口,用于编辑/创建某些对象,
mod-win2
: a modal window opened from mod-win1
, as a custom file selector. mod-win2
:从mod-win1
打开的模式窗口,作为自定义文件选择器。
mod-win2
is created/opened on a button click on mod-win1
, this is actioned in the layout controller for this window. 在单击
mod-win1
的按钮上创建/打开mod-win2
,这是在此窗口的布局控制器中进行的。 mod-win1
passes a reference to itself to mod-win2
which mod-win2
uses to call a close method when needed (on cancel/select). mod-win1
将自身的引用传递给mod-win2
, mod-win2
在需要时(在取消/选择时)使用它来调用close方法。
The problem is that whenever the window is closed, it makes a 'blurp' sound - I know, petty, but it's aggravating me! 问题是,每当关闭窗口时,它都会发出“嗡嗡”的声音-我知道,这很琐碎,但它使我感到烦恼! It's the same sound that the locked window behind the modal window makes if you try to click on it, so I'm thinking it's because I'm going back to the layout controller for the locked window in order to close the current one.
如果您尝试单击模态窗口,则它与锁定窗口后的锁定窗口发出的声音相同,因此,我想这是因为我要回到锁定窗口的布局控制器以关闭当前窗口。 All my other modal windows close silently, they're not created from within the layout controller of another window!
我所有其他模态窗口均以无提示方式关闭,它们不是在另一个窗口的布局控制器中创建的!
Can anyone confirm if this would cause this noise? 谁能确认这是否会引起这种噪音?
Also, is there a way to get a window to close itself (from within its layout controller) so I don't have to access the calling object? 另外,是否有一种方法可以使窗口自行关闭(从其布局控制器内部),因此我不必访问调用对象? ...or should I be creating an entirely new object to enclose all the file selector functionality and then calling that object (rather than the
mod-win1
layout controller) to close the window? ...或者我应该创建一个全新的对象来封装所有文件选择器功能,然后调用该对象(而不是
mod-win1
布局控制器)来关闭窗口?
A Stage can be closed any time by calling its close method. 舞台可以随时通过调用其close方法关闭。 I cannot reproduce your blurping sounds on my Windows 10 machine using JDK1.8.0_92.
我无法使用JDK1.8.0_92在Windows 10计算机上重现您的模糊声音。 But check out this example:
但是请查看以下示例:
package com.isp.stackoverflow;/**
* Created by okr on 13.07.2016.
*/
import javafx.application.Application;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.layout.StackPane;
import javafx.stage.Modality;
import javafx.stage.Stage;
public class ModalWindowsClosing extends Application
{
public static void main( String[] args )
{
launch( args );
}
@Override
public void start( Stage primaryStage )
{
final Button btn = new Button( "click me!" );
btn.setOnAction( __ ->
{
final Stage dialog = new Stage();
final Button dialogBtn = new Button( "click me again, fool!" );
dialogBtn.setOnAction( ___ ->
{
final Button closeBtn = new Button( "close dialog" );
closeBtn.setOnAction( ____ -> dialog.close() );
final Stage innerDialog = new Stage();
innerDialog.initOwner( dialog );
innerDialog.initModality( Modality.APPLICATION_MODAL );
innerDialog.setScene( new Scene( new StackPane( closeBtn ) ) );
innerDialog.show();
} );
dialog.initOwner( primaryStage );
dialog.initModality( Modality.APPLICATION_MODAL );
dialog.setScene( new Scene( new StackPane( dialogBtn ) ) );
dialog.show();
} );
primaryStage.setScene( new Scene( new StackPane( btn ) ) );
primaryStage.show();
}
}
My guess is, that you have not setup the window owners correctly, but without example code, that is impossible to tell. 我的猜测是,您没有正确设置窗口所有者,但是如果没有示例代码,这是很难告诉的。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.