【问题标题】:Stage styling in javafxjavafx 中的舞台样式
【发布时间】:2018-09-06 03:46:26
【问题描述】:

如何将 StageStyle.utility 和 StageStyle.undecorated 应用到同一个阶段。

我将它用于内部窗口/弹出窗口。

或者,如果我必须遵循任何其他解决方案,请尽量做到。

谢谢

【问题讨论】:

  • 没有问题。请添加您的问题。见stackoverflow.com/help/how-to-ask
  • 我想创建一个内部窗口/弹出窗口。如何创建它?窗口应该是未装饰的,也应该是无标题的#fireandfuel
  • 没有StageStyle.UNTITLED 这样的东西(见docs)。 UNDECORATED 舞台无论如何都没有标题。
  • @James_D 抱歉,它是 StageStyle.UTILITY
  • 我猜你需要根据你的条件隐藏窗口的标题UNDECORATEDUTILITY对于同一个舞台,你有一个解决方案来制作你的舞台UNDECORATED并添加一个按钮TOP_RIGHT.

标签: java javafx popupwindow scene stage


【解决方案1】:

您的问题:

同一阶段应用StageStyle.UTILITYStageStyle.UNDECORATED两种样式。

因为

您要求提供建议 来解决你的问题。

建议:

我建议使用in-sideFX/Undecorator (Downlaod the jar file and add it into your project),然后我们将进行一些修改以满足您的需要,我尝试创建此代码示例以在父窗口(所有者窗口)中创建弹出窗口: 包javafxpopup;

import insidefx.undecorator.Undecorator;
import javafx.application.Application;
import javafx.event.ActionEvent;
import javafx.event.EventHandler;
import javafx.scene.Node;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.control.Label;
import javafx.scene.layout.StackPane;
import javafx.stage.Stage;
import javafx.stage.StageStyle;

/**
 *
 * @author Menai Ala Eddine
 */
public class Undecorated extends Application {

    @Override
    public void start(Stage primaryStage) {
        Button btn = new Button();
        btn.setText("Click");
        btn.setOnAction(new EventHandler<ActionEvent>() {

            @Override
            public void handle(ActionEvent event) {
                Stage popStage = new Stage();
                popStage.initStyle(StageStyle.TRANSPARENT);
                StackPane root = new StackPane();
                root.getChildren().add(new Label("I'm popup window"));
                applyModification(popStage, root);
                popStage.show();

            }
        });

        StackPane root = new StackPane();
        root.getChildren().add(btn);        
        primaryStage.setScene(new Scene(root,500,500));
        primaryStage.setTitle("Hello World!");
        primaryStage.show();
    }

    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) {
        launch(args);
    }

    private void applyModification(Stage primaryStage, StackPane root) {
        Undecorator undecorator = new Undecorator(primaryStage, root);
        undecorator.getStylesheets().add("/skin/undecorator.css");
        Scene scene = new Scene(undecorator, 300, 250);
        primaryStage.setScene(scene);
        scene.setFill(null);
        Node stageMenu = undecorator.lookup("#StageMenu");
        stageMenu.setVisible(false);
        Node maximize = undecorator.lookup(".decoration-button-maximize");
        maximize.setVisible(false);
        Node manimize = undecorator.lookup(".decoration-button-minimize");
        manimize.setVisible(false);
        Node restore = undecorator.lookup(".decoration-button-fullscreen");
        restore.setVisible(false);

    }

}

单击按钮,弹出窗口将显示在所有者窗口中:

正如您在同一时间看到的StageStyle.UNDECORATEDStageStyle.UTILITY

PS:建议您可以找到很多解决方案。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2013-05-14
    • 1970-01-01
    • 2017-12-17
    • 1970-01-01
    • 2016-12-13
    • 1970-01-01
    • 1970-01-01
    • 2015-05-21
    相关资源
    最近更新 更多