JavaFX 8任务栏图标监听器 [英] JavaFX 8 Taskbar Icon Listener

查看:925
本文介绍了JavaFX 8任务栏图标监听器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

描述:我使用StageStyle.Undecorated窗口样式创建了一个javafx 8应用程序。我目前有一个最小化,最大化和全屏按钮,以及一个用于最大化窗口的组合监听器。

DESCRIPTION: I created a javafx 8 application with the StageStyle.Undecorated window styling. I currently have a minimize, maximize and fullscreen button, as well as a key combination listener for maximizing the window.

问题:有没有办法将监听器附加到任务栏图标,所以反过来我可以通过左键单击图标来最小化应用程序窗口?

QUESTION: Is there a way to attach a listener to the taskbar icon, so in turn I can minimize the application window by left-clicking on the icon?

推荐答案

将OnMousePressed事件处理程序添加到包含您的图标的节点,然后将您希望执行的方法添加到处理程序中!

Add an OnMousePressed event handler to the node containing your icon, then add the method you wish to execute to the handler!

任务栏示例!!

public static HBox createButtons(String id, int amount, int width, int height) {
        Rectangle[] button = new Rectangle[3];
        DropShadow glow = new DropShadow();
        HBox buttonBox = new HBox(10);

        glow.setSpread(.6);
        glow.setRadius(10);

        buttonBox.getStylesheets().add(Styles.styledToolBarCss);
        buttonBox.setId(id);
        buttonBox.setAlignment(Pos.TOP_RIGHT);

        button[0] = new Rectangle();
        button[0].setFill(new ImagePattern(ImagesAndIcons.minimize));
        button[0].setWidth(width);
        button[0].setHeight(height);
        button[0].setOnMouseEntered(e ->{
            glow.setColor(Color.DODGERBLUE);
            button[0].setEffect(glow);
        });
        button[0].setOnMouseExited(e ->{
            button[0].setEffect(null);
        });
        button[0].setOnMouseReleased(e ->{
            TileMapEditor.minimize();
        });

        button[1] = new Rectangle();
        button[1].setFill(new ImagePattern(ImagesAndIcons.maximize));
        button[1].setWidth(width);
        button[1].setHeight(height);
        button[1].setOnMouseEntered(e ->{
            glow.setColor(Color.DODGERBLUE);
            button[1].setEffect(glow);
        });
        button[1].setOnMouseExited(e ->{
            button[1].setEffect(null);
        });
        button[1].setOnMouseReleased(e ->{
            TileMapEditor.maximize();
        });

        button[2] = new Rectangle();
        button[2].setFill(new ImagePattern(ImagesAndIcons.exit));
        button[2].setWidth(width*1.5);
        button[2].setHeight(height);
        button[2].setOnMouseEntered(e ->{
            glow.setColor(Color.RED);
            button[2].setEffect(glow);
        });
        button[2].setOnMouseExited(e ->{
            button[2].setEffect(null);
        });
        button[2].setOnMouseReleased(e ->{
            TileMapEditor.exit();
        });

        buttonBox.getChildren().setAll(button);

        return buttonBox;
    }

这篇关于JavaFX 8任务栏图标监听器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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