{"id":640,"date":"2021-01-10T20:14:18","date_gmt":"2021-01-10T20:14:18","guid":{"rendered":"https:\/\/bhiggs.x10hosting.com\/PracticalJavaProgramming\/?page_id=640"},"modified":"2021-01-10T21:58:32","modified_gmt":"2021-01-10T21:58:32","slug":"panes-text-fonts","status":"publish","type":"page","link":"https:\/\/bhiggs.x10hosting.com\/PracticalJavaProgramming\/course-topics\/graphics-programming\/panes-text-fonts\/","title":{"rendered":"Panes, Text &#038; Fonts"},"content":{"rendered":"<div id=\"ez-toc-container\" class=\"ez-toc-v2_0_83 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-6a06f5f873762\" 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-6a06f5f873762\"  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\/graphics-programming\/panes-text-fonts\/#JFrame_Internal_Structure\" >JFrame Internal Structure<\/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\/graphics-programming\/panes-text-fonts\/#Graphics_Context\" >Graphics Context<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-3\" href=\"https:\/\/bhiggs.x10hosting.com\/PracticalJavaProgramming\/course-topics\/graphics-programming\/panes-text-fonts\/#Displaying_Text\" >Displaying Text<\/a><ul class='ez-toc-list-level-4' ><li class='ez-toc-heading-level-4'><a class=\"ez-toc-link ez-toc-heading-4\" href=\"https:\/\/bhiggs.x10hosting.com\/PracticalJavaProgramming\/course-topics\/graphics-programming\/panes-text-fonts\/#The_paintComponentmethod\" >The&nbsp;paintComponent()method<\/a><\/li><\/ul><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-5\" href=\"https:\/\/bhiggs.x10hosting.com\/PracticalJavaProgramming\/course-topics\/graphics-programming\/panes-text-fonts\/#Text_Fonts\" >Text &amp; Fonts<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-6\" href=\"https:\/\/bhiggs.x10hosting.com\/PracticalJavaProgramming\/course-topics\/graphics-programming\/panes-text-fonts\/#Mixing_Fonts\" >Mixing Fonts<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-7\" href=\"https:\/\/bhiggs.x10hosting.com\/PracticalJavaProgramming\/course-topics\/graphics-programming\/panes-text-fonts\/#Finding_Displaying_Fonts\" >Finding &amp; Displaying Fonts<\/a><\/li><\/ul><\/nav><\/div>\n\n<p>So how do we add content to a&nbsp;<code><strong>JFrame<\/strong><\/code>&nbsp;?<\/p>\n\n\n\n<p>As we&#8217;ll see here, we need to learn about:<\/p>\n\n\n\n<ul class=\"wp-block-list\"><li><strong><em>Panes<\/em><\/strong>&nbsp;(sometimes called&nbsp;<strong><em>Panels<\/em><\/strong>)<\/li><\/ul>\n\n\n\n<p>and then we&#8217;ll learn how to display&nbsp;<em><strong>text<\/strong><\/em>, and control that display using&nbsp;<em><strong>fonts<\/strong><\/em>.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"JFrame_Internal_Structure\"><\/span>JFrame Internal Structure<span class=\"ez-toc-section-end\"><\/span><\/h3>\n\n\n\n<p>A&nbsp;<code><strong>JFrame<\/strong><\/code>&nbsp;is quite a complex beast if you look at the number of&nbsp;<em>panes<\/em>&nbsp;it has associated with it:<\/p>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"alignleft size-large\"><img fetchpriority=\"high\" decoding=\"async\" width=\"576\" height=\"439\" src=\"https:\/\/bhiggs.x10hosting.com\/PracticalJavaProgramming\/wp-content\/uploads\/2021\/01\/AnatomyOfAJFrame.gif\" alt=\"\" class=\"wp-image-644\"\/><\/figure><\/div>\n\n\n\n<div style=\"height:30px\" aria-hidden=\"true\" class=\"wp-block-spacer\"><\/div>\n\n\n\n<p>Suffice it to say that there is only one pane of interest to us at this point:<\/p>\n\n\n\n<ul class=\"wp-block-list\"><li>The&nbsp;<em><strong>content pane<\/strong><\/em>.&nbsp;&nbsp;<\/li><\/ul>\n\n\n\n<p>The <em>content pane<\/em> is where you place the content of the frame (surprise!).&nbsp;&nbsp;<\/p>\n\n\n\n<blockquote class=\"wp-block-quote is-layout-flow wp-block-quote-is-layout-flow\"><p><strong><em><u>Note:<\/u><\/em><\/strong>&nbsp;This is unlike AWT, where you simply add your content directly to the frame itself.&nbsp;&nbsp;<\/p><\/blockquote>\n\n\n\n<p>You obtain the content pane by calling&nbsp;<strong><code>getContentPane()<\/code><\/strong>&nbsp;&#8212; again,  surprise!<\/p>\n\n\n\n<h3 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Graphics_Context\"><\/span>Graphics Context<span class=\"ez-toc-section-end\"><\/span><\/h3>\n\n\n\n<p>Before we go any further, one concept we need to understand is that of a&nbsp;<strong><em>graphics context<\/em><\/strong>, which in Java is represented by the&nbsp;<code><strong>Graphics<\/strong><\/code>&nbsp;class.<\/p>\n\n\n\n<p>What is a <em>graphics context<\/em>?<\/p>\n\n\n\n<p>Basically, it provides a context within which you can draw.&nbsp; As the&nbsp;<code><strong>Graphics<\/strong><\/code>&nbsp;class documents (see the Java API javadocs), it encapsulates state information needed for the basic rendering operations that Java supports. This state information includes the following properties:<\/p>\n\n\n\n<ul class=\"wp-block-list\"><li>The&nbsp;<code><strong>Component<\/strong><\/code>&nbsp;object on which to draw.<\/li><li>A translation origin for rendering and clipping coordinates.<\/li><li>The current clip.<\/li><li>The current color.<\/li><li>The current font.<\/li><li>The current logical pixel operation function (XOR or Paint).<\/li><li>The current XOR alternation color (see later).<\/li><\/ul>\n\n\n\n<p>We will see how you can draw inside Java Swing frames, panels, and other GUI components.&nbsp; <\/p>\n\n\n\n<blockquote class=\"wp-block-quote is-layout-flow wp-block-quote-is-layout-flow\"><p>If you ever venture into printing from Java, you will find the same concept there, except that the context is focused not on a GUI window, but on a printable page.&nbsp; We won&#8217;t get into printing from Java in this course &#8212; that&#8217;s a more advanced topic.<\/p><\/blockquote>\n\n\n\n<p>For drawing on the screen, Java originally provided only the&nbsp;<code><strong>Graphics<\/strong><\/code>&nbsp;class, which is actually an&nbsp;<em>abstract base class<\/em>, from which all graphics context classes extend.&nbsp; You can see what it (or rather, a class that extends it) provides by going to its&nbsp;<a href=\"https:\/\/docs.oracle.com\/javase\/1.5.0\/docs\/api\/java\/awt\/Graphics.html\" target=\"_blank\" rel=\"noreferrer noopener\">javadoc page<\/a>.<\/p>\n\n\n\n<p>Java 1.2 and beyond adds the <em>Java 2D library,<\/em> which augments the ability to draw to a considerable degree.\u00a0 It uses\u00a0<code><strong>Graphics2D<\/strong><\/code>, which is another abstract class that extends the\u00a0<code><strong>Graphics<\/strong><\/code>\u00a0class.\u00a0 You can find the details at its\u00a0<a href=\"https:\/\/docs.oracle.com\/javase\/1.5.0\/docs\/api\/java\/awt\/Graphics2D.html\" target=\"_blank\" rel=\"noreferrer noopener\">javadoc page<\/a>.<\/p>\n\n\n\n<p><code><strong>Graphics2D<\/strong><\/code>&nbsp;provides much more sophisticated control over geometry, coordinate transformations, color management, and text layout.&nbsp; Thoroughly covering the Java 2D library could take up an entire semester course, so we won&#8217;t be going into detail on Java 2D.&nbsp; We may show some examples of Java 2D later.<\/p>\n\n\n\n<p>We&#8217;ll be seeing the use of a graphics context in lots of subsequent drawing examples.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Displaying_Text\"><\/span>Displaying Text<span class=\"ez-toc-section-end\"><\/span><\/h3>\n\n\n\n<h4 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"The_paintComponentmethod\"><\/span>The&nbsp;<strong>paintComponent()<\/strong>method<span class=\"ez-toc-section-end\"><\/span><\/h4>\n\n\n\n<p>In order to display text in a content pane, you have to:<\/p>\n\n\n\n<ol class=\"wp-block-list\"><li>Create a class that extends&nbsp;<code><strong>JPanel<\/strong><\/code><\/li><li>Implement&nbsp;<code><strong>paintComponent(Graphics g)<\/strong><\/code>&nbsp;in that class;&nbsp; this is where all the drawing of text occurs<ul><li>The first thing this method should do is call&nbsp;<code><strong>super.paintComponent(g)<\/strong><\/code>&nbsp;&#8212; if you don&#8217;t, you will most likely find that strange things happen.<\/li><li>The rest of the code in the method should cause graphic elements to be displayed &#8212; in this case, we&#8217;ll be displaying text.<\/li><\/ul><\/li><li>Finally:<ul><li>Create an instance of this class and add it to the <strong>JFrame<\/strong>&#8216;s content pane.<\/li><\/ul><\/li><\/ol>\n\n\n\n<blockquote class=\"wp-block-quote is-layout-flow wp-block-quote-is-layout-flow\"><p><strong><em><u>Note:<\/u><\/em><\/strong>&nbsp; In addition to the&nbsp;<code><strong>paintComponent(Graphics g)<\/strong><\/code>&nbsp;method, there is also a&nbsp;<code><strong>paint(Graphics g)<\/strong><\/code>&nbsp;method.&nbsp; Don&#8217;t get confused between the two methods:<\/p><\/blockquote>\n\n\n\n<ul class=\"wp-block-list\"><li>If you&#8217;re programming in Swing, use&nbsp;<code><strong>paintComponent<\/strong><\/code>&nbsp;&nbsp;<\/li><li>If you&#8217;re programming in AWT, use&nbsp;<code><strong>paint<\/strong><\/code><\/li><\/ul>\n\n\n\n<p>Here&#8217;s an example:<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: java; auto-links: false; highlight: [11,12,13,14,15,16,17,18]; title: ; quick-code: false; notranslate\" title=\"\">\npackage swingExamples;\n\nimport java.awt.Container;\nimport java.awt.Graphics;\n\nimport javax.swing.JFrame;\nimport javax.swing.JPanel;\n\nclass TextDisplayPanel extends JPanel\n{\n  public void paintComponent(Graphics g)\n  {\n    \/\/ Don&#039;t forget to do this!\n    super.paintComponent(g);\n    \/\/ Display the text in the panel\n    g.drawString(&quot;Hello from a Java Swing application!&quot;, 50, 80);\n  }\n}\n\nclass TextDisplayFrame extends JFrame\n{\n  public TextDisplayFrame()\n  {\n    setTitle(&quot;Text Display Frame&quot;);\n    setSize(300, 200);\n    setDefaultCloseOperation(EXIT_ON_CLOSE);\n    \/\/ Find the JFrame&#039;s content pane\n    Container contentPane = getContentPane();\n    \/\/ Add the TextDisplayPanel to the content pane\n    contentPane.add( new TextDisplayPanel() );\n  }\n}\n\npublic class TextDisplay\n{\n  public static void main(String&#x5B;] args)\n  {\n    TextDisplayFrame frame = new TextDisplayFrame();\n    frame.setVisible(true);\n  }\n}\n<\/pre><\/div>\n\n\n<p>Here&#8217;s the result:<\/p>\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\/TextDisplayFrame.gif\" alt=\"\" class=\"wp-image-647\"\/><\/figure><\/div>\n\n\n\n<div style=\"height:28px\" aria-hidden=\"true\" class=\"wp-block-spacer\"><\/div>\n\n\n\n<h3 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Text_Fonts\"><\/span>Text &amp; Fonts<span class=\"ez-toc-section-end\"><\/span><\/h3>\n\n\n\n<p>Now, let&#8217;s say you want to display the text in a different way &#8212; perhaps using a particular font:<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: java; auto-links: false; highlight: [4,15,16]; title: ; quick-code: false; notranslate\" title=\"\">\npackage swingExamples;\n\nimport java.awt.Container;\nimport java.awt.Font;\nimport java.awt.Graphics;\n\nimport javax.swing.JFrame;\nimport javax.swing.JPanel;\n\nclass BoldTextDisplayPanel extends JPanel\n{\n  public void paintComponent(Graphics g)\n  {\n    super.paintComponent(g);\n    Font font = new Font(&quot;Serif&quot;, Font.BOLD, 16);\n    g.setFont(font);\n    g.drawString(&quot;Hello from a Java Swing application!&quot;, 20, 80);\n  }\n}\n\nclass BoldTextDisplayFrame extends JFrame\n{\n  public BoldTextDisplayFrame()\n  {\n    setTitle(&quot;Font Display Frame&quot;);\n    setSize(300, 200);\n    setDefaultCloseOperation(EXIT_ON_CLOSE);\n    Container contentPane = getContentPane();\n    contentPane.add( new BoldTextDisplayPanel() );\n  }\n}\n\npublic class BoldTextDisplay\n{\n  public static void main(String&#x5B;] args)\n  {\n    BoldTextDisplayFrame frame = new BoldTextDisplayFrame();\n    frame.setVisible(true);\n  }\n}\n<\/pre><\/div>\n\n\n<p>which produces:<\/p>\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\/FontDisplayFrame.gif\" alt=\"\" class=\"wp-image-648\"\/><\/figure><\/div>\n\n\n\n<div style=\"height:27px\" aria-hidden=\"true\" class=\"wp-block-spacer\"><\/div>\n\n\n\n<h3 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Mixing_Fonts\"><\/span>Mixing Fonts<span class=\"ez-toc-section-end\"><\/span><\/h3>\n\n\n\n<p>We can get fancier, and mix and match fonts in the display, by using the&nbsp;<strong><code>Font<\/code><\/strong>&nbsp;and&nbsp;<strong><code>FontMetrics<\/code><\/strong>&nbsp;classes.<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: java; auto-links: false; highlight: [5,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32]; title: ; quick-code: false; notranslate\" title=\"\">\npackage swingExamples;\n\nimport java.awt.Container;\nimport java.awt.Font;\nimport java.awt.FontMetrics;\nimport java.awt.Graphics;\n\nimport javax.swing.JFrame;\nimport javax.swing.JPanel;\n\nclass FancyFontDisplayPanel extends JPanel\n{\n  public void paintComponent(Graphics g)\n  {\n    super.paintComponent(g);\n    Font f = new Font(&quot;Serif&quot;, Font.PLAIN, 14);\n    Font fi = new Font(&quot;Serif&quot;, Font.BOLD | Font.ITALIC, 14);\n    FontMetrics fm = g.getFontMetrics(f);\n    FontMetrics fim = g.getFontMetrics(fi);\n    String s1 = &quot;Hello from a &quot;;\n    String s2 = &quot;Java Swing &quot;;\n    String s3 = &quot;application!&quot;;\n    int cx = 20;\n    int cy = 80;\n    g.setFont(f);\n    g.drawString(s1, cx, cy);\n    cx += fm.stringWidth(s1);\n    g.setFont(fi);\n    g.drawString(s2, cx, cy);\n    cx += fim.stringWidth(s2);\n    g.setFont(f);\n    g.drawString(s3, cx, cy);\n  }\n}\n\nclass FancyFontDisplayFrame extends JFrame\n{\n  public FancyFontDisplayFrame()\n  {\n    setTitle(&quot;FancyFontDisplayFrame&quot;);\n    setSize(300, 200);\n    setDefaultCloseOperation(EXIT_ON_CLOSE);\n    Container contentPane = getContentPane();\n    contentPane.add( new FancyFontDisplayPanel() );\n  }\n}\n\npublic class FancyFontDisplay\n{\n  public static void main(String&#x5B;] args)\n  {\n    FancyFontDisplayFrame frame = new FancyFontDisplayFrame();\n    frame.setVisible(true);\n  }\n}\n<\/pre><\/div>\n\n\n<p>which produces:<\/p>\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\/FancyFontDisplay.gif\" alt=\"\" class=\"wp-image-651\"\/><\/figure><\/div>\n\n\n\n<div style=\"height:22px\" aria-hidden=\"true\" class=\"wp-block-spacer\"><\/div>\n\n\n\n<p>However, this is clearly a pain in the neck to program!&nbsp; There are better mechanisms, but we won&#8217;t get to them in this course.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Finding_Displaying_Fonts\"><\/span>Finding &amp; Displaying Fonts<span class=\"ez-toc-section-end\"><\/span><\/h3>\n\n\n\n<p>There are only a small number of fonts that are guaranteed to be present in every Java environment:<\/p>\n\n\n\n<ul class=\"wp-block-list\"><li>Serif<\/li><li>SansSerif<\/li><li>Monospaced<\/li><li>Dialog<\/li><li>DialogInput<\/li><\/ul>\n\n\n\n<p>Each one of these is actually a&nbsp;<strong><em>logical<\/em><\/strong>&nbsp;font name, which is mapped to a specific platform-specific font on each platform.<\/p>\n\n\n\n<p>For JDK 1.1 and up, the following font names are deprecated (the replacement name follows):<\/p>\n\n\n\n<ul class=\"wp-block-list\"><li>TimesRoman (use Serif)<\/li><li>Helvetica (use SansSerif)<\/li><li>Courier (use Monospaced)<\/li><\/ul>\n\n\n\n<blockquote class=\"wp-block-quote is-layout-flow wp-block-quote-is-layout-flow\"><p>The ZapfDingbats font is also deprecated in 1.1 on up, but only as a separate font name.<\/p><\/blockquote>\n\n\n\n<p>Here&#8217;s a program that finds the fonts available to it, and displays them:<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: java; auto-links: false; highlight: [29,30,31,32,33,34,35,36,37,38,39,40,41,42,43]; title: ; quick-code: false; notranslate\" title=\"\">\npackage swingExamples;\n\nimport java.awt.Color;\nimport java.awt.Container;\nimport java.awt.Font;\nimport java.awt.FontMetrics;\nimport java.awt.Graphics;\nimport java.awt.Toolkit;\n\nimport javax.swing.JFrame;\nimport javax.swing.JPanel;\n\nclass AllFontsDisplayPanel extends JPanel\n{\n  public AllFontsDisplayPanel()\n  {\n    setBackground(Color.white);\n  }\n  \n  public void paintComponent(Graphics g)\n  {\n    super.paintComponent(g);\n    \n    int x = 10;\n    int y = 20;\n    Font font = null;\n    FontMetrics fm = null;\n    String fontString = null;\n    for (int i = 0; i &lt; m_font.length; i++)\n    {\n      String fontName = m_font&#x5B;i];\n      font = new Font(fontName, Font.PLAIN, 18);\n      g.setFont(font);\n      fm = g.getFontMetrics(font);\n      if (i &gt; 0)\n        y += fm.getAscent();\n      g.drawString( fontName, x, y );\n      y += fm.getDescent() + fm.getLeading();\n    }\n  }\n  \n  private String&#x5B;] m_font = \n          Toolkit.getDefaultToolkit().getFontList();\n}\n\nclass AllFontsDisplayFrame extends JFrame\n{\n  public AllFontsDisplayFrame()\n  {\n    setTitle(&quot;AllFontsDisplay&quot;);\n    setSize(300, 200);\n    setDefaultCloseOperation(EXIT_ON_CLOSE);\n    Container contentPane = getContentPane();\n    contentPane.add( new AllFontsDisplayPanel() );\n  }\n}\n\npublic class AllFontsDisplay\n{\n  public static void main(String&#x5B;] args)\n  {\n    AllFontsDisplayFrame frame = new AllFontsDisplayFrame();\n    frame.setVisible(true);\n  }\n}\n<\/pre><\/div>\n\n\n<p>and here&#8217;s what it produces on my Windows system:<\/p>\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\/AllFontsDisplay.gif\" alt=\"\" class=\"wp-image-652\"\/><\/figure><\/div>\n\n\n\n<div style=\"height:28px\" aria-hidden=\"true\" class=\"wp-block-spacer\"><\/div>\n\n\n\n<blockquote class=\"wp-block-quote is-layout-flow wp-block-quote-is-layout-flow\"><p>Note that the&nbsp;<code><strong>getFontList()<\/strong><\/code>&nbsp;method is deprecated.&nbsp; We will see a program later that uses the preferred replacement for this method.<\/p><\/blockquote>\n","protected":false},"excerpt":{"rendered":"<p>So how do we add content to a&nbsp;JFrame&nbsp;? As we&#8217;ll see here, we need to learn about: Panes&nbsp;(sometimes called&nbsp;Panels) and then we&#8217;ll learn how to display&nbsp;text, and control that display using&nbsp;fonts. JFrame Internal Structure A&nbsp;JFrame&nbsp;is quite a complex beast if you look at the number of&nbsp;panes&nbsp;it has associated with it: Suffice it to say that [&hellip;]<\/p>\n","protected":false},"author":2,"featured_media":0,"parent":67,"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-640","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":"So how do we add content to a&nbsp;JFrame&nbsp;? As we&#8217;ll see here, we need to learn about: Panes&nbsp;(sometimes called&nbsp;Panels) and then we&#8217;ll learn how to display&nbsp;text, and control that display using&nbsp;fonts. JFrame Internal Structure A&nbsp;JFrame&nbsp;is quite a complex beast if you look at the number of&nbsp;panes&nbsp;it has associated with it: Suffice it to say that&hellip;","_links":{"self":[{"href":"https:\/\/bhiggs.x10hosting.com\/PracticalJavaProgramming\/wp-json\/wp\/v2\/pages\/640","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=640"}],"version-history":[{"count":8,"href":"https:\/\/bhiggs.x10hosting.com\/PracticalJavaProgramming\/wp-json\/wp\/v2\/pages\/640\/revisions"}],"predecessor-version":[{"id":679,"href":"https:\/\/bhiggs.x10hosting.com\/PracticalJavaProgramming\/wp-json\/wp\/v2\/pages\/640\/revisions\/679"}],"up":[{"embeddable":true,"href":"https:\/\/bhiggs.x10hosting.com\/PracticalJavaProgramming\/wp-json\/wp\/v2\/pages\/67"}],"wp:attachment":[{"href":"https:\/\/bhiggs.x10hosting.com\/PracticalJavaProgramming\/wp-json\/wp\/v2\/media?parent=640"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}