{"id":672,"date":"2017-02-23T01:21:24","date_gmt":"2017-02-23T01:21:24","guid":{"rendered":"http:\/\/choudhury.com\/blog\/?p=672"},"modified":"2017-02-28T02:02:56","modified_gmt":"2017-02-28T02:02:56","slug":"javafx-undecorated-window-task-icon-minimize","status":"publish","type":"post","link":"https:\/\/choudhury.com\/blog\/2017\/02\/23\/javafx-undecorated-window-task-icon-minimize\/","title":{"rendered":"JavaFX Undecorated Window Task Icon Minimize"},"content":{"rendered":"<p>The JavaFX undecorated window gives you a blank canvas, giving freedom to how your window looks without having to accept the default Windows title bar and buttons such as the Minimize, Maximise and Close buttons.<\/p>\n<p>On Windows, the disadvantage of the Undecorated stage is if you click on the icon on the Taskbar, you don&#8217;t get the minimise behaviour compared to other Windows app. Likewise, if you use the keyboard shortcut  &#8220;Windows Key + M&#8221; all your apps except for the Undecorated JavaFX app will minimise. <\/p>\n<p>This can be quite fustrating.<\/p>\n<p><a href=\"https:\/\/choudhury.com\/blog\/wp-content\/uploads\/2017\/02\/minimise_task_icons.jpg\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-673\" src=\"https:\/\/choudhury.com\/blog\/wp-content\/uploads\/2017\/02\/minimise_task_icons.jpg\" alt=\"\" width=\"434\" height=\"140\" srcset=\"https:\/\/choudhury.com\/blog\/wp-content\/uploads\/2017\/02\/minimise_task_icons.jpg 434w, https:\/\/choudhury.com\/blog\/wp-content\/uploads\/2017\/02\/minimise_task_icons-300x97.jpg 300w\" sizes=\"auto, (max-width: 434px) 100vw, 434px\" \/><\/a><\/p>\n<p>There is a stackoverflow post on this issue:<\/p>\n<p><a href=\"http:\/\/stackoverflow.com\/questions\/26972683\/javafx-minimizing-undecorated-stage\">http:\/\/stackoverflow.com\/questions\/26972683\/javafx-minimizing-undecorated-stage<\/a><\/p>\n<p>This answer from StackOverflow post seems to work<\/p>\n<div class=\"codecolorer-container text default\" style=\"overflow:auto;white-space:nowrap;height:300px;\"><div class=\"text codecolorer\">import com.sun.jna.Pointer;<br \/>\nimport com.sun.jna.platform.win32.User32;<br \/>\nimport com.sun.jna.platform.win32.WinDef;<br \/>\nimport javafx.application.Application;<br \/>\nimport javafx.scene.Scene;<br \/>\nimport javafx.scene.control.Label;<br \/>\nimport javafx.scene.layout.Pane;<br \/>\nimport javafx.stage.Stage;<br \/>\nimport javafx.stage.StageStyle;<br \/>\n<br \/>\nimport static com.sun.jna.platform.win32.WinUser.GWL_STYLE;<br \/>\n<br \/>\npublic class SimpleWindowApplication extends Application {<br \/>\n<br \/>\n<br \/>\n<br \/>\n&nbsp; &nbsp; public static void main(String[] args) {<br \/>\n&nbsp; &nbsp; &nbsp; &nbsp; launch(args);<br \/>\n&nbsp; &nbsp; }<br \/>\n<br \/>\n&nbsp; &nbsp; @Override<br \/>\n&nbsp; &nbsp; public void start(final Stage stage) {<br \/>\n&nbsp; &nbsp; &nbsp; &nbsp; Scene scene = new Scene(new Pane(new Label(&quot;Hello World&quot;)));<br \/>\n&nbsp; &nbsp; &nbsp; &nbsp; stage.initStyle(StageStyle.UNDECORATED);<br \/>\n&nbsp; &nbsp; &nbsp; &nbsp; stage.setTitle(&quot;Find this window&quot;);<br \/>\n&nbsp; &nbsp; &nbsp; &nbsp; stage.setScene(scene);<br \/>\n&nbsp; &nbsp; &nbsp; &nbsp; stage.show();<br \/>\n&nbsp; &nbsp; &nbsp; &nbsp; long lhwnd = com.sun.glass.ui.Window.getWindows().get(0).getNativeWindow();<br \/>\n&nbsp; &nbsp; &nbsp; &nbsp; Pointer lpVoid = new Pointer(lhwnd);<br \/>\n&nbsp; &nbsp; &nbsp; &nbsp; WinDef.HWND hwnd = new WinDef.HWND(lpVoid);<br \/>\n&nbsp; &nbsp; &nbsp; &nbsp; final User32 user32 = User32.INSTANCE;<br \/>\n&nbsp; &nbsp; &nbsp; &nbsp; int oldStyle = user32.GetWindowLong(hwnd, GWL_STYLE);<br \/>\n&nbsp; &nbsp; &nbsp; &nbsp; System.out.println(Integer.toBinaryString(oldStyle));<br \/>\n&nbsp; &nbsp; &nbsp; &nbsp; int newStyle = oldStyle | 0x00020000;\/\/WS_MINIMIZEBOX<br \/>\n&nbsp; &nbsp; &nbsp; &nbsp; System.out.println(Integer.toBinaryString(newStyle));<br \/>\n&nbsp; &nbsp; &nbsp; &nbsp; user32.SetWindowLong(hwnd, GWL_STYLE, newStyle);<br \/>\n&nbsp; &nbsp; }<br \/>\n}<\/div><\/div>\n<p>It uses the JNA library add the WS_MINIMIZEBOX  style to the existing Window.<\/p>\n<p>Dependencies required if your using gradle are<\/p>\n<div class=\"codecolorer-container text default\" style=\"overflow:auto;white-space:nowrap;\"><div class=\"text codecolorer\">&nbsp; &nbsp; compile 'net.java.dev.jna:jna:4.3.0'<br \/>\n&nbsp; &nbsp; compile 'net.java.dev.jna:jna-platform:4.3.0'<\/div><\/div>\n<p><b> <\/b><br \/>\n<strong>Java 9<\/strong><\/p>\n<p>Java 9 modularity adds stronger encapsulation, if you attempt to run the sample program under Java 9,  you&#8217;ll get IllegalAccessError as the com.sun.glass.ui package is not visible to unnamed modules<\/p>\n<p>To make the example run on Java 9 you will need to add this additional VM Option<\/p>\n<div class=\"codecolorer-container text default\" style=\"overflow:auto;white-space:nowrap;\"><div class=\"text codecolorer\">--add-exports=javafx.graphics\/com.sun.glass.ui=ALL-UNNAMED<\/div><\/div>\n","protected":false},"excerpt":{"rendered":"<p>The JavaFX undecorated window gives you a blank canvas, giving freedom to how your window looks without having to accept the default Windows title bar and buttons such as the Minimize, Maximise and Close buttons. On Windows, the disadvantage of the Undecorated stage is if you click on the icon on the Taskbar, you don&#8217;t &hellip; <\/p>\n<p class=\"link-more\"><a href=\"https:\/\/choudhury.com\/blog\/2017\/02\/23\/javafx-undecorated-window-task-icon-minimize\/\" class=\"more-link\">Continue reading<span class=\"screen-reader-text\"> &#8220;JavaFX Undecorated Window Task Icon Minimize&#8221;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_jetpack_memberships_contains_paid_content":false,"footnotes":""},"categories":[3,5],"tags":[],"class_list":["post-672","post","type-post","status-publish","format-standard","hentry","category-java","category-javafx"],"jetpack_featured_media_url":"","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/choudhury.com\/blog\/wp-json\/wp\/v2\/posts\/672","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/choudhury.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/choudhury.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/choudhury.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/choudhury.com\/blog\/wp-json\/wp\/v2\/comments?post=672"}],"version-history":[{"count":11,"href":"https:\/\/choudhury.com\/blog\/wp-json\/wp\/v2\/posts\/672\/revisions"}],"predecessor-version":[{"id":689,"href":"https:\/\/choudhury.com\/blog\/wp-json\/wp\/v2\/posts\/672\/revisions\/689"}],"wp:attachment":[{"href":"https:\/\/choudhury.com\/blog\/wp-json\/wp\/v2\/media?parent=672"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/choudhury.com\/blog\/wp-json\/wp\/v2\/categories?post=672"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/choudhury.com\/blog\/wp-json\/wp\/v2\/tags?post=672"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}