亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

具有模態的舞臺隱藏最大化按鈕

具有模態的舞臺隱藏最大化按鈕

楊__羊羊 2023-09-13 15:23:18
當我設置舞臺的模式時,它會隱藏最大化按鈕Stage stage = new Stage();stage.setScene(new Scene((Parent) controller.getViewNode()));stage.initStyle(StageStyle.DECORATED);stage.setResizable(true);stage.setIconified(false);stage.initModality(Modality.APPLICATION_MODAL);stage.initOwner(window);所以我希望舞臺是一個模態,但也顯示最大化按鈕,但不會發生什么。順便說一句,我正在使用 Ubuntu。我已經進行了搜索,但我只找到了如何刪除最大化按鈕
查看完整描述

1 回答

?
繁華開滿天機

TA貢獻1816條經驗 獲得超4個贊

我也遇到同樣的情況。如果我嘗試最大化使用

stage.setMaximized(true);

它不起作用,最大化按鈕也不顯示。我正在研究這個問題,但根本沒有答案。這是我在這里發現的第一個類似問題。我在用著:

  • 操作系統:GNU/Linux

  • 發行版:Manjaro

  • Linux 核心:5.3.6-1

  • 來自:侏儒。

  • Java版本:OpenJDK 12.0.1

  • JavaFX 版本:OpenJFX 12.0.1(膠子構建)。

更新:官方文檔指出:

請注意,顯示模態階段并不一定會阻止調用者。

因此,我決定使用 EventHandler 來解決該問題。我創建了一個實用程序類來處理這個問題。

import javafx.event.Event;

import javafx.stage.Stage;

import javafx.stage.WindowEvent;


/**

 * This is a utility class to create a Widow Event handler

 * in such way that when a child window shows, a parent (owner)

 * stage get locked; and when the child window hides, the parent

 * stage get unlocked.

 *

 * @author David Vidal

 * @version 1.0

 * @since 1.0

 */

public final class WindowsModality {

    /*=================*

     * Private fields. *

     *=================*/

    /**

     * The parent stage.

     */

    private final Stage owner;


    /*===============*

     * Constructors. *

     *===============*/


    /**

     * Initialize an instance with given parameters.

     *

     * @param owner parent stage.

     * @param child child stage.

     */

    public WindowsModality(Stage owner, Stage child) {

        this.owner = owner;

        child.addEventHandler(WindowEvent.WINDOW_HIDDEN, this::childHidden);

        child.addEventHandler(WindowEvent.WINDOW_SHOWN, this::childShown);

    }


    /*==================*

     * Implementations. *

     *==================*/


    /**

     * Implementation of functional interface EventHandler,

     * used to know when the child window is closed/hidden.

     *

     * @param event from {@link javafx.event.EventHandler#handle(Event)}

     */

    private void childHidden(WindowEvent event) {

        if (!event.isConsumed()) {

            owner.getScene().getRoot().setDisable(false);

        }

    }


    /**

     * Implementation of functional interface EventHandler,

     * used to know when the child window is shown.

     *

     * @param event from {@link javafx.event.EventHandler#handle(Event)}

     */

    private void childShown(WindowEvent event) {

        if (!event.isConsumed()) {

            owner.getScene().getRoot().setDisable(true);

        }

    }

}

然后,我剛剛添加了以下代碼:


public void showAnotherStage(){

    //(Create and setup the new stage and scene)

    

    new WindowModality(primaryStage, newStage);

    newStage.show();

    

    //Do something else.

}

這是我的解決方案,經過測試并且工作正常。當顯示子窗口(newStage)時,所有者(primaryStage)將被禁用,因此盡管用戶可以激活primaryStage窗口,但用戶無法與其節點交互。


查看完整回答
反對 回復 2023-09-13
  • 1 回答
  • 0 關注
  • 116 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號