描述:我使用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任务栏图标监听器
发布评论