JavaFX 8任务栏图标监听器

编程入门 行业动态 更新时间:2024-10-27 23:19:20
本文介绍了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任务栏图标监听器

本文发布于:2023-11-13 12:24:48,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1584353.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:监听器   任务栏   图标   JavaFX

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!