Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/batch-file/6.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
弹出窗口卡在主窗口后面-JavaFX_Java_Javafx_Window - Fatal编程技术网

弹出窗口卡在主窗口后面-JavaFX

弹出窗口卡在主窗口后面-JavaFX,java,javafx,window,Java,Javafx,Window,所以这个问题有点棘手。此类用于在我的主程序中为用户可能执行的潜在危险操作生成警告窗口。这个窗口的好处是,如果用户单击OK,那么它将返回true到我的主类。这是通过以下方式实现的: private boolean showWarningWindow(String message) { ConfirmationBox warning = new ConfirmationBox(message); warning.showAndWait(); if (warning.

所以这个问题有点棘手。此类用于在我的主程序中为用户可能执行的潜在危险操作生成警告窗口。这个窗口的好处是,如果用户单击OK,那么它将返回true到我的主类。这是通过以下方式实现的:

    private boolean showWarningWindow(String message)
{
    ConfirmationBox warning = new ConfirmationBox(message);
    warning.showAndWait();

    if (warning.isSelected())
    {
        return true;
    }

    return false;
}
这个方法在我的主GUI类中。问题在下面的
确认框中。行
initmodel(model.APPLICATION\u model)无法正常工作。如果您不小心单击返回到原始GUI窗口,那么您就完了,因为现在您的确认框窗口被困在主窗口下,并且由于
模态.APPLICATION\u MODAL
,您将无法单击任何东西以返回窗口。您的任务栏上没有单独的应用程序来恢复窗口的焦点,您甚至无法使用alt tab来尝试修复它

显然,
模态。应用程序_模态
可以工作,但不知何故,它没有建立中断主窗口所需的连接

在您自己的应用程序中尝试。将
showWarningWindow
方法添加到应用程序中,并添加ConfirmationWindow类,您将明白我的意思。我不太确定如何解决这个问题

package application;

import javafx.beans.property.*;
import javafx.geometry.*;
import javafx.scene.Scene;
import javafx.scene.control.*;
import javafx.scene.layout.*;
import javafx.stage.*;

public class ConfirmationBox extends Stage
{
    private VBox layout = new VBox();

    private ReadOnlyBooleanWrapper selected = new ReadOnlyBooleanWrapper();

    public boolean isSelected()
    {
        return selected.get();
    }

    public ReadOnlyBooleanProperty selectedProperty()
    {
        return selected.getReadOnlyProperty();
    }

    public ConfirmationBox(String question)
    {
        // Core functionality of the ConfirmationBox.
        setTitle("Warning");
        initStyle(StageStyle.UTILITY);
        initModality(Modality.APPLICATION_MODAL);
        setResizable(false);

        layout.setSpacing(10);
        layout.setPadding(new Insets(10));

        createControls();

        // Add the Label and Buttons to the Confirmation Box.
        layout.getChildren().addAll(new Label(question + "\n\n\n"), createControls());

        java.awt.Toolkit.getDefaultToolkit().beep();
        setScene(new Scene(layout));
        sizeToScene();  // workaround because utility stages aren't automatically sized correctly to their scene.
    }

    private HBox createControls()
    {
        final Button ok = new Button("OK");
        ok.setOnAction(e -> {
            selected.set(true);
            close();
        });

        final Button cancel = new Button("Cancel");
        cancel.setOnAction(e -> {
            selected.set(false);
            close();
        });

        final HBox controls = new HBox(10, ok, cancel);
        controls.setAlignment(Pos.CENTER_RIGHT);

        return controls;
    }
}

尝试添加对
initOwner(…)
的调用,传入对主窗口的引用。(我会测试,但我不在电脑旁。)我也想过。我会给它一个机会,然后报告我的发现。哇,真是太棒了。你是上帝。非常感谢。