{"id":884,"date":"2013-08-22T10:44:11","date_gmt":"2013-08-22T08:44:11","guid":{"rendered":"https:\/\/mihosoft.eu\/?p=884"},"modified":"2013-08-22T10:45:12","modified_gmt":"2013-08-22T08:45:12","slug":"adding-custom-icons-to-jfxtras-window-control-vfxwindows","status":"publish","type":"post","link":"https:\/\/mihosoft.eu\/?p=884","title":{"rendered":"Adding Custom Icons to JFXtras Window Control (VFXWindows)"},"content":{"rendered":"<h2>Adding custom Icons:<\/h2>\n\n<p>The window control comes with some predefined icons. But it is also possible to provide custom icons.<\/p>\n\n<p>To add a custom icon just add it via either <code>getRightIcons().add(myIcon)<\/code> or <code>getLeftIcons().add(myIcon)<\/code>. The action of an icon can be defined by defining an <code>EventHandler<\/code> via <code>setOnAction(..)<\/code>.<\/p>\n\n<h2>Example:<\/h2>\n\n<pre><code>    WindowIcon customIcon = new WindowIcon();\n    customIcon.setOnAction(new EventHandler&lt;ActionEvent&gt;() {\n        @Override\n        public void handle(ActionEvent t) {\n            \/\/ we add a nice scale transition\n            \/\/ (it doesn't do anything useful but it is cool!)\n            ScaleTransition st = new ScaleTransition(Duration.seconds(2), w);\n            st.setFromX(w.getScaleX());\n            st.setFromY(w.getScaleY());\n            st.setToX(0.1);\n            st.setToY(0.1);\n            st.setAutoReverse(true);\n            st.setCycleCount(2);\n            st.play();\n        }\n    });\n\n    \/\/ now we add our custom icon\n    w.getRightIcons().add(customIcon);\n<\/code><\/pre>\n\n<p>The result will look like this:<\/p>\n\n<div id=\"attachment_885\" style=\"width: 310px\" class=\"wp-caption aligncenter\"><a href=\"https:\/\/mihosoft.eu\/wp-content\/uploads\/2013\/08\/window-control-custom-icons-01.png\"><img aria-describedby=\"caption-attachment-885\" decoding=\"async\" loading=\"lazy\" src=\"https:\/\/mihosoft.eu\/wp-content\/uploads\/2013\/08\/window-control-custom-icons-01-300x211.png\" alt=\"Window Control: Custom Icon\" width=\"300\" height=\"211\" class=\"size-medium wp-image-885\" srcset=\"https:\/\/mihosoft.eu\/wp-content\/uploads\/2013\/08\/window-control-custom-icons-01-300x211.png 300w, https:\/\/mihosoft.eu\/wp-content\/uploads\/2013\/08\/window-control-custom-icons-01.png 587w\" sizes=\"(max-width: 300px) 100vw, 300px\" \/><\/a><p id=\"caption-attachment-885\" class=\"wp-caption-text\">Window Control: Custom Icon<\/p><\/div>\n\n<h2>Tip:<\/h2>\n\n<p>It is recommended to use CSS to style the icon. The best way to do this is by specifying an SVG path in the style. To do so use <code>-fx-shape<\/code> and paste the path there. Here is an example how it is done for the <code>CloseIcon<\/code>:<\/p>\n\n<p>First, define the style class:<\/p>\n\n<pre><code> customIcon.getStyleClass().setAll(\"window-close-icon\");\n<\/code><\/pre>\n\n<p>And here&#8217;s the corresponding entry in the CSS file:<\/p>\n\n<pre><code>.window-close-icon {\n  -fx-skin: \"jfxtras.labs.internal.scene.control.skin.window.DefaultWindowIconSkin\";\n  -fx-border-color: rgb(255,255,255);\n  -fx-shape: \"m 81.451435,47.885404 -39.71427,39.714277 m 0,-39.714277 39.71427,39.714277 m 27.285725,-19.85714 c 0,26.03628 -21.106585,47.142859 -47.142865,47.142859 -26.03628,0 -47.14285,-21.106579 -47.14285,-47.142859 0,-26.036277 21.10657,-47.142853 47.14285,-47.142853 26.03628,0 47.142865,21.106576 47.142865,47.142853 z\";\n  -fx-border-width: 2;\n  -fx-border-insets: 1;\n}\n<\/code><\/pre>\n\n<h2>Conclusion<\/h2>\n\n<p>As you have seen it is not complicated to add custom icons to the window control. The behavior of the icons is fully customizable. <\/p>\n\n<h2>Fedback<\/h2>\n\n<p>If you have further questions or if you found a bug feel free to contact me! You are also welcome to contribute to the project via <a href=\"https:\/\/github.com\/JFXtras\/jfxtras-labs\">GitHub<\/a>.<\/p>\n\n<p>Stay tuned and <a href=\"https:\/\/twitter.com\/intent\/user?screen_name=mihosoft\">follow me on Twitter<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Adding custom Icons: The window control comes with some predefined icons. But it is also possible to provide custom icons. To add a custom icon just add it via either getRightIcons().add(myIcon) or getLeftIcons().add(myIcon). The action of an icon can be defined by defining an EventHandler via setOnAction(..). Example: WindowIcon customIcon &#8230;<\/p>","protected":false},"author":1,"featured_media":885,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"jetpack_post_was_ever_published":false,"jetpack_publicize_message":"","jetpack_is_tweetstorm":false,"jetpack_publicize_feature_enabled":true},"categories":[129,21,1,5],"tags":[22,124,51,26,25,61,53,27,30,55,56],"jetpack_publicize_connections":[],"jetpack_featured_media_url":"https:\/\/mihosoft.eu\/wp-content\/uploads\/2013\/08\/window-control-custom-icons-01.png","jetpack_shortlink":"https:\/\/wp.me\/p2P2yR-eg","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/mihosoft.eu\/index.php?rest_route=\/wp\/v2\/posts\/884"}],"collection":[{"href":"https:\/\/mihosoft.eu\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/mihosoft.eu\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/mihosoft.eu\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/mihosoft.eu\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=884"}],"version-history":[{"count":10,"href":"https:\/\/mihosoft.eu\/index.php?rest_route=\/wp\/v2\/posts\/884\/revisions"}],"predecessor-version":[{"id":895,"href":"https:\/\/mihosoft.eu\/index.php?rest_route=\/wp\/v2\/posts\/884\/revisions\/895"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/mihosoft.eu\/index.php?rest_route=\/wp\/v2\/media\/885"}],"wp:attachment":[{"href":"https:\/\/mihosoft.eu\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=884"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/mihosoft.eu\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=884"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/mihosoft.eu\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=884"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}