{"id":773,"date":"2021-01-11T18:16:26","date_gmt":"2021-01-11T18:16:26","guid":{"rendered":"https:\/\/bhiggs.x10hosting.com\/PracticalJavaProgramming\/?page_id=773"},"modified":"2021-01-11T18:40:59","modified_gmt":"2021-01-11T18:40:59","slug":"pluggable-look-feel","status":"publish","type":"page","link":"https:\/\/bhiggs.x10hosting.com\/PracticalJavaProgramming\/course-topics\/events\/pluggable-look-feel\/","title":{"rendered":"Pluggable Look &#038; Feel"},"content":{"rendered":"<div id=\"ez-toc-container\" class=\"ez-toc-v2_0_85 counter-hierarchy ez-toc-counter ez-toc-grey ez-toc-container-direction\">\n<p class=\"ez-toc-title\" style=\"cursor:inherit\">Table of Contents<\/p>\n<label for=\"ez-toc-cssicon-toggle-item-6a3e1d6c93a70\" class=\"ez-toc-cssicon-toggle-label\"><span class=\"\"><span class=\"eztoc-hide\" style=\"display:none;\">Toggle<\/span><span class=\"ez-toc-icon-toggle-span\"><svg style=\"fill: #999;color:#999\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\" class=\"list-377408\" width=\"20px\" height=\"20px\" viewBox=\"0 0 24 24\" fill=\"none\"><path d=\"M6 6H4v2h2V6zm14 0H8v2h12V6zM4 11h2v2H4v-2zm16 0H8v2h12v-2zM4 16h2v2H4v-2zm16 0H8v2h12v-2z\" fill=\"currentColor\"><\/path><\/svg><svg style=\"fill: #999;color:#999\" class=\"arrow-unsorted-368013\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"10px\" height=\"10px\" viewBox=\"0 0 24 24\" version=\"1.2\" baseProfile=\"tiny\"><path d=\"M18.2 9.3l-6.2-6.3-6.2 6.3c-.2.2-.3.4-.3.7s.1.5.3.7c.2.2.4.3.7.3h11c.3 0 .5-.1.7-.3.2-.2.3-.5.3-.7s-.1-.5-.3-.7zM5.8 14.7l6.2 6.3 6.2-6.3c.2-.2.3-.5.3-.7s-.1-.5-.3-.7c-.2-.2-.4-.3-.7-.3h-11c-.3 0-.5.1-.7.3-.2.2-.3.5-.3.7s.1.5.3.7z\"\/><\/svg><\/span><\/span><\/label><input type=\"checkbox\"  id=\"ez-toc-cssicon-toggle-item-6a3e1d6c93a70\"  aria-label=\"Toggle\" \/><nav><ul class='ez-toc-list ez-toc-list-level-1 ' ><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-1\" href=\"https:\/\/bhiggs.x10hosting.com\/PracticalJavaProgramming\/course-topics\/events\/pluggable-look-feel\/#Example\" >Example<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-2\" href=\"https:\/\/bhiggs.x10hosting.com\/PracticalJavaProgramming\/course-topics\/events\/pluggable-look-feel\/#Metal_Themes\" >Metal &amp; Themes<\/a><ul class='ez-toc-list-level-4' ><li class='ez-toc-heading-level-4'><a class=\"ez-toc-link ez-toc-heading-3\" href=\"https:\/\/bhiggs.x10hosting.com\/PracticalJavaProgramming\/course-topics\/events\/pluggable-look-feel\/#Themes\" >Themes<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-4'><a class=\"ez-toc-link ez-toc-heading-4\" href=\"https:\/\/bhiggs.x10hosting.com\/PracticalJavaProgramming\/course-topics\/events\/pluggable-look-feel\/#Synth\" >Synth<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-4'><a class=\"ez-toc-link ez-toc-heading-5\" href=\"https:\/\/bhiggs.x10hosting.com\/PracticalJavaProgramming\/course-topics\/events\/pluggable-look-feel\/#Future_Efforts\" >Future Efforts<\/a><\/li><\/ul><\/li><\/ul><\/nav><\/div>\n\n<p class=\"wp-block-paragraph\">In <em>JDK 1.2<\/em> and beyond, it&#8217;s possible, using <em>Swing<\/em>, to change the way things appear and behave.&nbsp; This is commonly known as <em>&#8220;Look and Feel&#8221;<\/em>, or <em>LAF<\/em>, or <em>L&amp;F<\/em>.&nbsp; Each platform has its own specific look and feel, and many, including Microsoft Windows and Apple Macintosh, are protected by patents, etc.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">JavaSoft came up with their own, platform-neutral L&amp;F, originally called <em>Metal<\/em>, but now simply called the <em>Java L&amp;F<\/em>, which is available on all platforms.&nbsp; They have also implemented the <em>Microsoft Windows LAF<\/em>, the <em>Motif LAF<\/em>, and the <em>Macintosh LAF<\/em>.&nbsp; However, because of legal issues, the Microsoft Windows and Macintosh LAFs are only available on their respective platforms.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">By default, Java programs display with the <em>Java L&amp;F<\/em>.&nbsp; You can change this by setting the&nbsp;<code><strong>swing.defaultlaf<\/strong><\/code>&nbsp;property to the fully-qualified name of the desired L&amp;F class.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">You can also specify the desired L&amp;F at run time.&nbsp; One approach is to set the L&amp;F at the beginning of your Java program.&nbsp; Another is to change the L&amp;F completely dynamically.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Example\"><\/span>Example<span class=\"ez-toc-section-end\"><\/span><\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">Here&#8217;s a program that allows you to dynamically switch between various LAFs:<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: java; auto-links: false; highlight: [16,17,18,19,33,34,35,36,37,38,39,40,41,42,43,44,45,46,47,48,49,50,51,52,53,54,55]; title: ; quick-code: false; notranslate\" title=\"\">\npackage swingExamples;\n\nimport java.awt.event.ActionEvent;\nimport java.awt.event.ActionListener;\nimport javax.swing.JButton;\nimport javax.swing.JFrame;\nimport javax.swing.JPanel;\nimport javax.swing.SwingUtilities;\nimport javax.swing.UIManager;\nimport javax.swing.UnsupportedLookAndFeelException;\n\nclass LookAndFeelPanel extends JPanel\n{\n  public LookAndFeelPanel()\n  {\n    UIManager.LookAndFeelInfo&#x5B;] feels = \n             UIManager.getInstalledLookAndFeels();\n    for (UIManager.LookAndFeelInfo feel: feels)\n      makeButton( feel.getName(), feel.getClassName() );\n  }\n  \n  private void makeButton(String feelName, \n                          final String feelClassName)\n  {\n    JButton button = new JButton(feelName);\n    add(button);\n    \n    button.addActionListener( \n      new ActionListener()\n      {\n        public void actionPerformed(ActionEvent event)\n        {\n          try\n          {\n            UIManager.setLookAndFeel(feelClassName);\n          } \n          catch (ClassNotFoundException ex)\n          {\n            ex.printStackTrace();\n          } \n          catch (InstantiationException ex)\n          {\n            ex.printStackTrace();\n          } \n          catch (IllegalAccessException ex)\n          {\n            ex.printStackTrace();\n          } \n          catch (UnsupportedLookAndFeelException ex)\n          {\n            ex.printStackTrace();\n          }\n              \n          SwingUtilities.updateComponentTreeUI(\n                                 LookAndFeelPanel.this);\n        }\n      }\n    );\n  }\n}\n\nclass LookAndFeelFrame extends JFrame\n{\n  public LookAndFeelFrame()\n  {\n    setTitle(&quot;Setting Look and Feel&quot;);\n    setSize(300, 200);\n    LookAndFeelPanel panel = new LookAndFeelPanel();\n    getContentPane().add(panel);\n  }\n}\n\npublic class LookAndFeelDisplay\n{\n  public static void main(String&#x5B;] args)\n  {\n    JFrame frame = new LookAndFeelFrame();\n    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);\n    frame.setVisible(true);\n  }\n}\n<\/pre><\/div>\n\n\n<p class=\"wp-block-paragraph\">Here is a what it shows me on my Windows system, for Java 1.6:<\/p>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"alignleft size-large\"><img fetchpriority=\"high\" decoding=\"async\" width=\"300\" height=\"200\" src=\"https:\/\/bhiggs.x10hosting.com\/PracticalJavaProgramming\/wp-content\/uploads\/2021\/01\/Plugga14.jpg\" alt=\"\" class=\"wp-image-777\"\/><\/figure><\/div>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"alignleft size-large\"><img decoding=\"async\" width=\"300\" height=\"200\" src=\"https:\/\/bhiggs.x10hosting.com\/PracticalJavaProgramming\/wp-content\/uploads\/2021\/01\/Plugga15.jpg\" alt=\"\" class=\"wp-image-778\"\/><\/figure><\/div>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"alignleft size-large\"><img decoding=\"async\" width=\"300\" height=\"200\" src=\"https:\/\/bhiggs.x10hosting.com\/PracticalJavaProgramming\/wp-content\/uploads\/2021\/01\/Plugga16.jpg\" alt=\"\" class=\"wp-image-779\"\/><\/figure><\/div>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"alignleft size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"300\" height=\"200\" src=\"https:\/\/bhiggs.x10hosting.com\/PracticalJavaProgramming\/wp-content\/uploads\/2021\/01\/Plugga17.jpg\" alt=\"\" class=\"wp-image-780\"\/><\/figure><\/div>\n\n\n\n<div style=\"height:22px\" aria-hidden=\"true\" class=\"wp-block-spacer\"><\/div>\n\n\n\n<p class=\"wp-block-paragraph\">You can tell which LAF is which by looking at the button that has the current focus. (Of course, each L&amp;F has its own way of indicating that.)<\/p>\n\n\n\n<blockquote class=\"wp-block-quote is-layout-flow wp-block-quote-is-layout-flow\"><p><strong>Note:<\/strong> In JDK 1.4.2, JavaSoft added a GTK+ L&amp;F (GTK+ is a popular GUI interface for Linux).&nbsp; Unfortunately, it doesn&#8217;t seem to have made it into JDK 1.5, or 1.6, at least in the Microsoft Windows release.<\/p><\/blockquote>\n\n\n\n<h3 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Metal_Themes\"><\/span>Metal &amp; Themes<span class=\"ez-toc-section-end\"><\/span><\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">The original Java Look and Feel was code-named &#8220;Metal&#8221;, and that&#8217;s pretty much what it looked like.&nbsp; It was very flat (two-dimensional), dull, colorless, and generally pretty boring, especially when compared with current GUI L&amp;Fs on Windows and on various Linux systems. Here&#8217;s an example of the original &#8220;Metal&#8221; look and feel, an image from the <em>SwingSet<\/em> demo:<\/p>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"alignleft size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"728\" height=\"727\" src=\"https:\/\/bhiggs.x10hosting.com\/PracticalJavaProgramming\/wp-content\/uploads\/2021\/01\/MetalT18.jpg\" alt=\"\" class=\"wp-image-781\" srcset=\"https:\/\/bhiggs.x10hosting.com\/PracticalJavaProgramming\/wp-content\/uploads\/2021\/01\/MetalT18.jpg 728w, https:\/\/bhiggs.x10hosting.com\/PracticalJavaProgramming\/wp-content\/uploads\/2021\/01\/MetalT18-300x300.jpg 300w, https:\/\/bhiggs.x10hosting.com\/PracticalJavaProgramming\/wp-content\/uploads\/2021\/01\/MetalT18-150x150.jpg 150w\" sizes=\"(max-width: 728px) 100vw, 728px\" \/><\/figure><\/div>\n\n\n\n<div style=\"height:30px\" aria-hidden=\"true\" class=\"wp-block-spacer\"><\/div>\n\n\n\n<p class=\"wp-block-paragraph\">The marketing people decided, in their infinite wisdom, to call &#8220;Metal&#8221; the <em>&#8220;Java Look and Feel&#8221;<\/em> (what imagination!), but most people continued to refer to it as &#8220;Metal&#8221;.<\/p>\n\n\n\n<h4 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Themes\"><\/span>Themes<span class=\"ez-toc-section-end\"><\/span><\/h4>\n\n\n\n<p class=\"wp-block-paragraph\">Then, in Java 5.0 (a.k.a. 1.5), the Java developers added the concept of &#8220;Themes&#8221; to the &#8220;Metal&#8221; Look and Feel, and made the default theme be one called &#8220;Ocean&#8221;.&nbsp;The original Metal default became the &#8220;Steel&#8221; theme.&nbsp;<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">What you&#8217;ve seen so far in most of the examples, is the Ocean theme of the Java Look and Feel.&nbsp; Here&#8217;s what &#8220;Ocean&#8221; looks like, to contrast it with the above:<\/p>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"alignleft size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"728\" height=\"727\" src=\"https:\/\/bhiggs.x10hosting.com\/PracticalJavaProgramming\/wp-content\/uploads\/2021\/01\/MetalT19.jpg\" alt=\"\" class=\"wp-image-782\" srcset=\"https:\/\/bhiggs.x10hosting.com\/PracticalJavaProgramming\/wp-content\/uploads\/2021\/01\/MetalT19.jpg 728w, https:\/\/bhiggs.x10hosting.com\/PracticalJavaProgramming\/wp-content\/uploads\/2021\/01\/MetalT19-300x300.jpg 300w, https:\/\/bhiggs.x10hosting.com\/PracticalJavaProgramming\/wp-content\/uploads\/2021\/01\/MetalT19-150x150.jpg 150w\" sizes=\"(max-width: 728px) 100vw, 728px\" \/><\/figure><\/div>\n\n\n\n<div style=\"height:23px\" aria-hidden=\"true\" class=\"wp-block-spacer\"><\/div>\n\n\n\n<p class=\"wp-block-paragraph\">A definite improvement, although it&#8217;s still pretty two-dimensional.&nbsp; At least the buttons are made to look like they have a three-dimensional component.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">For more details about Metal themes, see&nbsp;<a rel=\"noreferrer noopener\" href=\"https:\/\/docs.oracle.com\/javase\/1.5.0\/docs\/api\/javax\/swing\/plaf\/metal\/MetalLookAndFeel.html\" target=\"_blank\">here<\/a>.<\/p>\n\n\n\n<h4 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Synth\"><\/span>Synth<span class=\"ez-toc-section-end\"><\/span><\/h4>\n\n\n\n<p class=\"wp-block-paragraph\">The newest look and feel for the Java 5 release is called <em>&#8220;Synth&#8221;<\/em>.&nbsp; It allows you to customize your own look and feel by means of an XML file, instead of having to perform lots of nitty-gritty coding in lots of different places.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">The <em>Synth<\/em> look and feel class is:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"><strong>javax.swing.plaf.synth.SynthLookAndFeel<\/strong><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">and you can find its API&nbsp;<a href=\"https:\/\/docs.oracle.com\/javase\/1.5.0\/docs\/api\/javax\/swing\/plaf\/synth\/SynthLookAndFeel.html\" target=\"_blank\" rel=\"noreferrer noopener\">here<\/a>.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">How to use <em>Synth<\/em> is beyond the scope of this course, however.<\/p>\n\n\n\n<h4 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Future_Efforts\"><\/span>Future Efforts<span class=\"ez-toc-section-end\"><\/span><\/h4>\n\n\n\n<p class=\"wp-block-paragraph\">More definitely needs to be done, and people are working on it.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>In JDK 1.2 and beyond, it&#8217;s possible, using Swing, to change the way things appear and behave.&nbsp; This is commonly known as &#8220;Look and Feel&#8221;, or LAF, or L&amp;F.&nbsp; Each platform has its own specific look and feel, and many, including Microsoft Windows and Apple Macintosh, are protected by patents, etc. JavaSoft came up with [&hellip;]<\/p>\n","protected":false},"author":2,"featured_media":0,"parent":69,"menu_order":0,"comment_status":"closed","ping_status":"closed","template":"","meta":{"_eb_attr":"","_uag_custom_page_level_css":"","ocean_post_layout":"left-sidebar","ocean_both_sidebars_style":"","ocean_both_sidebars_content_width":0,"ocean_both_sidebars_sidebars_width":0,"ocean_sidebar":"ocs-course-topics-sidebar","ocean_second_sidebar":"0","ocean_disable_margins":"enable","ocean_add_body_class":"","ocean_shortcode_before_top_bar":"","ocean_shortcode_after_top_bar":"","ocean_shortcode_before_header":"","ocean_shortcode_after_header":"","ocean_has_shortcode":"","ocean_shortcode_after_title":"","ocean_shortcode_before_footer_widgets":"","ocean_shortcode_after_footer_widgets":"","ocean_shortcode_before_footer_bottom":"","ocean_shortcode_after_footer_bottom":"","ocean_display_top_bar":"default","ocean_display_header":"default","ocean_header_style":"","ocean_center_header_left_menu":"0","ocean_custom_header_template":"0","ocean_custom_logo":0,"ocean_custom_retina_logo":0,"ocean_custom_logo_max_width":0,"ocean_custom_logo_tablet_max_width":0,"ocean_custom_logo_mobile_max_width":0,"ocean_custom_logo_max_height":0,"ocean_custom_logo_tablet_max_height":0,"ocean_custom_logo_mobile_max_height":0,"ocean_header_custom_menu":"0","ocean_menu_typo_font_family":"0","ocean_menu_typo_font_subset":"","ocean_menu_typo_font_size":0,"ocean_menu_typo_font_size_tablet":0,"ocean_menu_typo_font_size_mobile":0,"ocean_menu_typo_font_size_unit":"px","ocean_menu_typo_font_weight":"","ocean_menu_typo_font_weight_tablet":"","ocean_menu_typo_font_weight_mobile":"","ocean_menu_typo_transform":"","ocean_menu_typo_transform_tablet":"","ocean_menu_typo_transform_mobile":"","ocean_menu_typo_line_height":0,"ocean_menu_typo_line_height_tablet":0,"ocean_menu_typo_line_height_mobile":0,"ocean_menu_typo_line_height_unit":"","ocean_menu_typo_spacing":0,"ocean_menu_typo_spacing_tablet":0,"ocean_menu_typo_spacing_mobile":0,"ocean_menu_typo_spacing_unit":"","ocean_menu_link_color":"","ocean_menu_link_color_hover":"","ocean_menu_link_color_active":"","ocean_menu_link_background":"","ocean_menu_link_hover_background":"","ocean_menu_link_active_background":"","ocean_menu_social_links_bg":"","ocean_menu_social_hover_links_bg":"","ocean_menu_social_links_color":"","ocean_menu_social_hover_links_color":"","ocean_disable_title":"default","ocean_disable_heading":"default","ocean_post_title":"","ocean_post_subheading":"","ocean_post_title_style":"","ocean_post_title_background_color":"","ocean_post_title_background":0,"ocean_post_title_bg_image_position":"","ocean_post_title_bg_image_attachment":"","ocean_post_title_bg_image_repeat":"","ocean_post_title_bg_image_size":"","ocean_post_title_height":0,"ocean_post_title_bg_overlay":0.5,"ocean_post_title_bg_overlay_color":"","ocean_disable_breadcrumbs":"default","ocean_breadcrumbs_color":"","ocean_breadcrumbs_separator_color":"","ocean_breadcrumbs_links_color":"","ocean_breadcrumbs_links_hover_color":"","ocean_display_footer_widgets":"default","ocean_display_footer_bottom":"default","ocean_custom_footer_template":"0","footnotes":""},"class_list":["post-773","page","type-page","status-publish","hentry","entry"],"uagb_featured_image_src":{"full":false,"thumbnail":false,"medium":false,"medium_large":false,"large":false,"1536x1536":false,"2048x2048":false,"ocean-thumb-m":false,"ocean-thumb-ml":false,"ocean-thumb-l":false},"uagb_author_info":{"display_name":"Bryan Higgs","author_link":"https:\/\/bhiggs.x10hosting.com\/PracticalJavaProgramming\/author\/bryan\/"},"uagb_comment_info":0,"uagb_excerpt":"In JDK 1.2 and beyond, it&#8217;s possible, using Swing, to change the way things appear and behave.&nbsp; This is commonly known as &#8220;Look and Feel&#8221;, or LAF, or L&amp;F.&nbsp; Each platform has its own specific look and feel, and many, including Microsoft Windows and Apple Macintosh, are protected by patents, etc. JavaSoft came up with&hellip;","_links":{"self":[{"href":"https:\/\/bhiggs.x10hosting.com\/PracticalJavaProgramming\/wp-json\/wp\/v2\/pages\/773","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/bhiggs.x10hosting.com\/PracticalJavaProgramming\/wp-json\/wp\/v2\/pages"}],"about":[{"href":"https:\/\/bhiggs.x10hosting.com\/PracticalJavaProgramming\/wp-json\/wp\/v2\/types\/page"}],"author":[{"embeddable":true,"href":"https:\/\/bhiggs.x10hosting.com\/PracticalJavaProgramming\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/bhiggs.x10hosting.com\/PracticalJavaProgramming\/wp-json\/wp\/v2\/comments?post=773"}],"version-history":[{"count":7,"href":"https:\/\/bhiggs.x10hosting.com\/PracticalJavaProgramming\/wp-json\/wp\/v2\/pages\/773\/revisions"}],"predecessor-version":[{"id":788,"href":"https:\/\/bhiggs.x10hosting.com\/PracticalJavaProgramming\/wp-json\/wp\/v2\/pages\/773\/revisions\/788"}],"up":[{"embeddable":true,"href":"https:\/\/bhiggs.x10hosting.com\/PracticalJavaProgramming\/wp-json\/wp\/v2\/pages\/69"}],"wp:attachment":[{"href":"https:\/\/bhiggs.x10hosting.com\/PracticalJavaProgramming\/wp-json\/wp\/v2\/media?parent=773"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}