如何从任务栏中删除我的javafx程序 [英] How can I remove my javafx program from the taskbar

查看:185
本文介绍了如何从任务栏中删除我的javafx程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要从任务栏中删除我的javafx应用。我试过 StageStyle.UTILITY 。这是有效的,但我需要UNDECORATED和UTILITY舞台风格或其他解决方案。
感谢您的回复。

I need remove my javafx app from the taskbar. I tried StageStyle.UTILITY. This is works but I need both UNDECORATED and UTILITY stage styles or another solvings. Thank you for your replies.

推荐答案

对不起,您已经等了这么久才得到某种答案这个,以下主要是针对那些希望找到实现这一目标的人来到这里。

Sorry you've been waiting so long for some sort of an answer on this, the following is mainly for people who come to this in the future hoping to discover a way of achieving this.

让我先说我不会考虑以下解决方案,但更多的解决方法。
不能为舞台分配多个 initStyle 但是从任务栏中隐藏应用程序并分配 initStyle 除了显示的舞台的实用程序以外。

Let me start of by saying I wouldn't consider the following a solution but more of a workaround. Assigning more than one initStyle to a stage is not possible however hiding the application from the task-bar and assigning an initStyle other than utility to the stage that is shown is.

要实现这一点,必须创建两个阶段,即用户希望用户看到的阶段,以及另一个阶段将被视为主阶段的父级,并且将是 initStyle.UTILITY 这将阻止图标显示在任务栏中。

To achieve this one must create two stages, the stage they want the user to see, and an another stage that will be considered the parent of the main stage and will be of initStyle.UTILITY this will prevent the icon from showing in the task-bar.

下面你可以看到oracles文档中的hello world示例被修改为允许没有图标的未修饰窗口(注意,如果想要实现透明/装饰窗口,他们可以通过更改样式 mainStage )。

Below you can see the hello world example from oracles documentation modified to allow for an undecorated window with no icon (Note if one wanted to achieve a transparent/decorated window they could do so by changing the style of mainStage).

import javafx.application.Application;
import javafx.event.ActionEvent;
import javafx.event.EventHandler;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.layout.StackPane;
import javafx.stage.Stage;
import javafx.stage.StageStyle;


public class MultipleStageStyles extends Application {

    public static void main(String[] args) {
        launch(args);
    }

    @Override
    public void start(Stage primaryStage) {
        primaryStage.initStyle(StageStyle.UTILITY);
        primaryStage.setOpacity(0);
        primaryStage.setHeight(0);
        primaryStage.setWidth(0);
        primaryStage.show();
        Stage mainStage = new Stage();
        mainStage.initOwner(primaryStage);
        mainStage.initStyle(StageStyle.UNDECORATED);
        Button btn = new Button();
        btn.setText("Say 'Hello World'");
        btn.setOnAction(new EventHandler<ActionEvent>() {
            @Override
            public void handle(ActionEvent event) {
                System.out.println("Hello World!");
            }
        });
        StackPane root = new StackPane();
        root.getChildren().add(btn);
        mainStage.setScene(new Scene(root, 300, 250));
        mainStage.show();
    }
}

这篇关于如何从任务栏中删除我的javafx程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆