{"id":1114,"date":"2021-01-13T16:25:23","date_gmt":"2021-01-13T16:25:23","guid":{"rendered":"https:\/\/bhiggs.x10hosting.com\/PracticalJavaProgramming\/?page_id=1114"},"modified":"2021-01-13T17:04:46","modified_gmt":"2021-01-13T17:04:46","slug":"more-on-layout-management","status":"publish","type":"page","link":"https:\/\/bhiggs.x10hosting.com\/PracticalJavaProgramming\/course-topics\/swing-gui-components\/more-on-layout-management\/","title":{"rendered":"More on Layout Management"},"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-6a3f970281fba\" 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-6a3f970281fba\"  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\/swing-gui-components\/more-on-layout-management\/#BoxLayout\" >BoxLayout<\/a><ul class='ez-toc-list-level-4' ><li class='ez-toc-heading-level-4'><a class=\"ez-toc-link ez-toc-heading-2\" href=\"https:\/\/bhiggs.x10hosting.com\/PracticalJavaProgramming\/course-topics\/swing-gui-components\/more-on-layout-management\/#Example_1\" >Example 1<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-4'><a class=\"ez-toc-link ez-toc-heading-3\" href=\"https:\/\/bhiggs.x10hosting.com\/PracticalJavaProgramming\/course-topics\/swing-gui-components\/more-on-layout-management\/#Example_2\" >Example 2<\/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\/swing-gui-components\/more-on-layout-management\/#Example_3\" >Example 3<\/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\/swing-gui-components\/more-on-layout-management\/#Example_4\" >Example 4<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-4'><a class=\"ez-toc-link ez-toc-heading-6\" href=\"https:\/\/bhiggs.x10hosting.com\/PracticalJavaProgramming\/course-topics\/swing-gui-components\/more-on-layout-management\/#Example_5\" >Example 5<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-4'><a class=\"ez-toc-link ez-toc-heading-7\" href=\"https:\/\/bhiggs.x10hosting.com\/PracticalJavaProgramming\/course-topics\/swing-gui-components\/more-on-layout-management\/#Example_6\" >Example 6<\/a><\/li><\/ul><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-8\" href=\"https:\/\/bhiggs.x10hosting.com\/PracticalJavaProgramming\/course-topics\/swing-gui-components\/more-on-layout-management\/#GridBagLayout\" >GridBagLayout<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-9\" href=\"https:\/\/bhiggs.x10hosting.com\/PracticalJavaProgramming\/course-topics\/swing-gui-components\/more-on-layout-management\/#SpringLayout\" >SpringLayout<\/a><\/li><\/ul><\/nav><\/div>\n\n<p class=\"wp-block-paragraph\">Here are some more layout managers that you can use.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Two recently introduced layout managers are&nbsp;<code><strong>BoxLayout<\/strong><\/code>&nbsp;and&nbsp;<code><strong>SpringLayout<\/strong><\/code>.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><code><strong>GridBagLayout<\/strong><\/code>, is often referred to as &#8220;the mother of all layout managers&#8221;.&nbsp; It is probably the most complex of all layout managers.&nbsp; It can do virtually any layout you would like, but not without putting up a good fight.&nbsp; It takes a long time to learn it, and once you&#8217;ve learnt it, you&#8217;ll still forget how to use it the next time you need it.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><code><strong>SpringLayout<\/strong><\/code>, in particular, is an attempt to create a more flexible layout manager without the difficulties created by trying to use&nbsp;<code><strong>GridBagLayout<\/strong><\/code>.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"BoxLayout\"><\/span>BoxLayout<span class=\"ez-toc-section-end\"><\/span><\/h3>\n\n\n\n<p class=\"wp-block-paragraph\"><code><strong>BoxLayout<\/strong><\/code>&nbsp;is a layout manager provided by Swing (unlike the other layout managers, it is located in the&nbsp;<code><strong>javax.swing<\/strong><\/code>&nbsp;package).<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><code><strong>BoxLayout<\/strong><\/code>&nbsp;arranges a sequence of components horizontally or vertically.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">For&nbsp;<em>vertical layouts<\/em>, here is what the <code><strong>BoxLayout<\/strong><\/code> manager does:<\/p>\n\n\n\n<ol class=\"wp-block-list\"><li>It computes the maximum width of the widest component.<\/li><li>It tries to grow all components horizontally to that width.<\/li><li>If a component does not actually grow to that width when requested, its x-alignment is queried by calling its&nbsp;<code><strong>getAlignmentX()<\/strong><\/code>&nbsp;method.&nbsp; This method returns a floating-point number between 0.0 (align left) and 1.0 (align right).&nbsp; The default in the <strong>Component<\/strong> class is 0.5 (center).&nbsp; The value is used to align the component horizontally.<\/li><li>The preferred height of each component is obtained.&nbsp; All preferred heights are added up.<\/li><li>If the total preferred height is less than the box height, then the components are expanded, by letting them grow to their maximum height.&nbsp; Components are then placed, from top to bottom, with no additional space between them.<br>If the total preferred height is greater than the box height, the components are shrunk, potentially down to their minimum height, but no further.<br>If the components don&#8217;t all fit at their minimum height, some of them will not be shown.<\/li><\/ol>\n\n\n\n<p class=\"wp-block-paragraph\">For&nbsp;<em>horizontal layouts<\/em>, the process is analogous.<\/p>\n\n\n\n<h4 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Example_1\"><\/span>Example 1<span class=\"ez-toc-section-end\"><\/span><\/h4>\n\n\n\n<p class=\"wp-block-paragraph\">Here&#8217;s an example of the use of <strong>BoxLayout<\/strong>:<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: java; auto-links: false; highlight: [5,16]; title: ; quick-code: false; notranslate\" title=\"\">\npackage swingExamples;\n\nimport java.awt.Container;\n\nimport javax.swing.BoxLayout;\nimport javax.swing.JButton;\nimport javax.swing.JFrame;\nimport javax.swing.JLabel;\nimport javax.swing.JPanel;\nimport javax.swing.JTextField;\n\nclass BoxLayoutExamplePanel extends JPanel\n{\n  public BoxLayoutExamplePanel()\n  {\n    setLayout( new BoxLayout(this, BoxLayout.Y_AXIS) );\n    add(new JButton(&quot;Click me&quot;));\n    add(new JLabel(&quot;I am a label&quot;));\n    add(new JTextField(&quot;Text field&quot;));\n    add(new JButton(&quot;A very long button label is this...&quot;));\n  }\n}\n\npublic class BoxLayoutExample1 extends JFrame\n{\n  public BoxLayoutExample1()\n  {\n    setDefaultCloseOperation(EXIT_ON_CLOSE);\n    setTitle(&quot;BoxLayout&quot;);\n    Container contentPane = getContentPane();\n    contentPane.add( new BoxLayoutExamplePanel() );\n  }\n  \n  public static void main(String&#x5B;] args)\n  {\n    JFrame frame = new BoxLayoutExample1();\n    frame.setSize(300, 200);\n    frame.setVisible(true);\n  }\n}\n<\/pre><\/div>\n\n\n<p class=\"wp-block-paragraph\">which produces the following:<\/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\/BoxLayoutExample1.gif\" alt=\"\" class=\"wp-image-1118\"\/><\/figure><\/div>\n\n\n\n<div style=\"height:26px\" aria-hidden=\"true\" class=\"wp-block-spacer\"><\/div>\n\n\n\n<h4 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Example_2\"><\/span>Example 2<span class=\"ez-toc-section-end\"><\/span><\/h4>\n\n\n\n<p class=\"wp-block-paragraph\">You&#8217;ll note that the&nbsp;<code><strong>JTextField<\/strong><\/code>&nbsp;in the previous example expands unreasonably, filling the remaining space.&nbsp; One solution to this is to set the maximum size of the component, as follows:<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: java; auto-links: false; highlight: [19,20]; title: ; quick-code: false; notranslate\" title=\"\">\npackage swingExamples;\n\nimport java.awt.Container;\n\nimport javax.swing.BoxLayout;\nimport javax.swing.JButton;\nimport javax.swing.JFrame;\nimport javax.swing.JLabel;\nimport javax.swing.JPanel;\nimport javax.swing.JTextField;\n\nclass BoxLayoutExamplePanel extends JPanel\n{\n  public BoxLayoutExamplePanel()\n  {\n    setLayout(new BoxLayout(this, BoxLayout.Y_AXIS));\n    add(new JButton(&quot;Click me&quot;));\n    add(new JLabel(&quot;I am a label&quot;));\n    JTextField textField = new JTextField(&quot;Text field&quot;, 20);\n    textField.setMaximumSize(textField.getPreferredSize());\n    add(textField);\n    add(new JButton(&quot;A very long button label is this...&quot;));\n  }\n}\n\npublic class BoxLayoutExample2 extends JFrame\n{\n  public BoxLayoutExample2()\n  {\n    setDefaultCloseOperation(EXIT_ON_CLOSE);\n    setTitle(&quot;BoxLayout&quot;);\n    Container contentPane = getContentPane();\n    contentPane.add(new BoxLayoutExamplePanel());\n  }\n  \n  public static void main(String&#x5B;] args)\n  {\n    JFrame frame = new BoxLayoutExample2();\n    frame.setSize(300, 200);\n    frame.setVisible(true);\n  }\n}\n<\/pre><\/div>\n\n\n<p class=\"wp-block-paragraph\">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\/BoxLayoutExample2.gif\" alt=\"\" class=\"wp-image-1122\"\/><\/figure><\/div>\n\n\n\n<div style=\"height:35px\" aria-hidden=\"true\" class=\"wp-block-spacer\"><\/div>\n\n\n\n<h4 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Example_3\"><\/span>Example 3<span class=\"ez-toc-section-end\"><\/span><\/h4>\n\n\n\n<p class=\"wp-block-paragraph\">Even now, the results doesn&#8217;t look like much.&nbsp; Everything is kind of scrunched together.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">We can improve things by using&nbsp;<strong>struts<\/strong>, which can introduce vertical or horizontal space:<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: java; auto-links: false; highlight: [19,21,25]; title: ; quick-code: false; notranslate\" title=\"\">\npackage swingExamples;\n\nimport java.awt.Container;\n\nimport javax.swing.Box;\nimport javax.swing.BoxLayout;\nimport javax.swing.JButton;\nimport javax.swing.JFrame;\nimport javax.swing.JLabel;\nimport javax.swing.JPanel;\nimport javax.swing.JTextField;\n\nclass BoxLayoutExamplePanel extends JPanel\n{\n  public BoxLayoutExamplePanel()\n  {\n    setLayout(new BoxLayout(this, BoxLayout.Y_AXIS));\n    add(new JButton(&quot;Click me&quot;));\n    add( Box.createVerticalStrut(10) );\n    add(new JLabel(&quot;I am a label&quot;));\n    add( Box.createVerticalStrut(5) );\n    JTextField textField = new JTextField(&quot;Text field&quot;, 20);\n    textField.setMaximumSize(textField.getPreferredSize());\n    add(textField);\n    add( Box.createVerticalStrut(40) );\n    add(new JButton(&quot;A very long button label is this...&quot;));\n  }\n}\n\npublic class BoxLayoutExample3 extends JFrame\n{\n  public BoxLayoutExample3()\n  {\n    setDefaultCloseOperation(EXIT_ON_CLOSE);\n    setTitle(&quot;BoxLayout&quot;);\n    Container contentPane = getContentPane();\n    contentPane.add(new BoxLayoutExamplePanel());\n  }\n  \n  public static void main(String&#x5B;] args)\n  {\n    JFrame frame = new BoxLayoutExample3();\n    frame.setSize(300, 200);\n    frame.setVisible(true);\n  }\n}\n<\/pre><\/div>\n\n\n<p class=\"wp-block-paragraph\">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\/BoxLayoutExample3.gif\" alt=\"\" class=\"wp-image-1126\"\/><\/figure><\/div>\n\n\n\n<div style=\"height:21px\" aria-hidden=\"true\" class=\"wp-block-spacer\"><\/div>\n\n\n\n<p class=\"wp-block-paragraph\">As you can see, the struts have introduced some vertical spacing between the components.<\/p>\n\n\n\n<h4 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Example_4\"><\/span>Example 4<span class=\"ez-toc-section-end\"><\/span><\/h4>\n\n\n\n<p class=\"wp-block-paragraph\">Before we go any further, we need to introduce the concept of combining horizontal and vertical box layouts. This is further simplified by the use of the <code><strong>Box<\/strong><\/code> container.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Let&#8217;s modify our example so that we are actually producing more meaningful content, and use both horizontal and vertical boxes:<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: java; auto-links: false; highlight: [5,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40,41,42,43,44,45,46,47,48,49,50,51]; title: ; quick-code: false; notranslate\" title=\"\">\npackage swingExamples;\n\nimport java.awt.BorderLayout;\nimport java.awt.Container;\nimport javax.swing.Box;\nimport javax.swing.JButton;\nimport javax.swing.JFrame;\nimport javax.swing.JLabel;\nimport javax.swing.JPanel;\nimport javax.swing.JTextField;\n\nclass BoxLayoutExamplePanel extends JPanel\n{\n  public BoxLayoutExamplePanel()\n  {\n    setLayout( new BorderLayout() );\n    \n    \/\/ Create a horizontal box &amp; populate it\n    Box hbox1 = Box.createHorizontalBox();\n    hbox1.add( new JLabel(&quot;Name:&quot;) );\n    hbox1.add( Box.createHorizontalStrut(10) );\n    JTextField nameTextField = new JTextField(10);\n    nameTextField.setMaximumSize( \n        nameTextField.getPreferredSize() );\n    hbox1.add(nameTextField);\n    \n    \/\/ Create another horizontal box &amp; populate it\n    Box hbox2 = Box.createHorizontalBox();\n    hbox2.add( new JLabel(&quot;Password:&quot;) );\n    hbox2.add( Box.createHorizontalStrut(10) );\n    JTextField passwordTextField = new JTextField(10);\n    passwordTextField.setMaximumSize( \n        passwordTextField.getPreferredSize() );\n    hbox2.add(passwordTextField);\n    \n    \/\/ Create yet another horizontal box &amp; populate it\n    Box hbox3 = Box.createHorizontalBox();\n    hbox3.add( new JButton(&quot;OK&quot;) );\n    hbox3.add( Box.createHorizontalStrut(10) );\n    hbox3.add( new JButton(&quot;Cancel&quot;) );\n    \n    \/\/ Now, create a vertical box, &amp; add the \n    \/\/ horizontal boxes to it.\n    Box vbox = Box.createVerticalBox();\n    vbox.add(hbox1);\n    vbox.add(hbox2);\n    vbox.add(hbox3);\n    \n    \/\/ Finally, add the vertical box to the center \n    \/\/ of the panel&#039;s border layout.\n    add(vbox, BorderLayout.CENTER);\n  }\n}\n\npublic class BoxLayoutExample4 extends JFrame\n{\n  public static void main(String&#x5B;] args)\n  {\n    JFrame frame = new BoxLayoutExample4();\n    frame.setSize(300, 200);\n    frame.setVisible(true);\n  }\n  public BoxLayoutExample4()\n  {\n    setDefaultCloseOperation(EXIT_ON_CLOSE);\n    setTitle(&quot;BoxLayout&quot;);\n    Container contentPane = getContentPane();\n    contentPane.add(new BoxLayoutExamplePanel());\n  }\n}\n<\/pre><\/div>\n\n\n<p class=\"wp-block-paragraph\">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\/BoxLayoutExample4.gif\" alt=\"\" class=\"wp-image-1130\"\/><\/figure><\/div>\n\n\n\n<div style=\"height:16px\" aria-hidden=\"true\" class=\"wp-block-spacer\"><\/div>\n\n\n\n<p class=\"wp-block-paragraph\">This is starting to produce more pleasing results!<\/p>\n\n\n\n<h4 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Example_5\"><\/span>Example 5<span class=\"ez-toc-section-end\"><\/span><\/h4>\n\n\n\n<p class=\"wp-block-paragraph\">We can change the layout further, by the use of&nbsp;<strong>rigid areas<\/strong>:<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: java; auto-links: false; highlight: [48,49]; title: ; quick-code: false; notranslate\" title=\"\">\npackage swingExamples;\n\nimport java.awt.BorderLayout;\nimport java.awt.Container;\nimport java.awt.Dimension;\nimport javax.swing.Box;\nimport javax.swing.JButton;\nimport javax.swing.JFrame;\nimport javax.swing.JLabel;\nimport javax.swing.JPanel;\nimport javax.swing.JTextField;\n\nclass BoxLayoutExamplePanel extends JPanel\n{\n  public BoxLayoutExamplePanel()\n  {\n    setLayout( new BorderLayout() );\n    \n    \/\/ Create a horizontal box &amp; populate it\n    Box hbox1 = Box.createHorizontalBox();\n    hbox1.add( new JLabel(&quot;Name:&quot;) );\n    hbox1.add( Box.createHorizontalStrut(10) );\n    JTextField nameTextField = new JTextField(10);\n    nameTextField.setMaximumSize( \n        nameTextField.getPreferredSize() );\n    hbox1.add(nameTextField);\n    \n    \/\/ Create another horizontal box &amp; populate it\n    Box hbox2 = Box.createHorizontalBox();\n    hbox2.add( new JLabel(&quot;Password:&quot;) );\n    hbox2.add( Box.createHorizontalStrut(10) );\n    JTextField passwordTextField = new JTextField(10);\n    passwordTextField.setMaximumSize( \n        passwordTextField.getPreferredSize() );\n    hbox2.add(passwordTextField);\n    \n    \/\/ Create yet another horizontal box &amp; populate it\n    Box hbox3 = Box.createHorizontalBox();\n    hbox3.add( new JButton(&quot;OK&quot;) );\n    hbox3.add( Box.createHorizontalStrut(10) );\n    hbox3.add( new JButton(&quot;Cancel&quot;) );\n    \n    \/\/ Now, create a vertical box, &amp; \n    \/\/ add the horizontal boxes to it.\n    Box vbox = Box.createVerticalBox();\n    vbox.add(hbox1);\n    vbox.add(hbox2);\n    vbox.add( Box.createRigidArea( \n        new Dimension(10, 80) ) );\n    vbox.add(hbox3);\n    \n    \/\/ Finally, add the vertical box to the \n    \/\/ center of the panel&#039;s border layout.\n    add(vbox, BorderLayout.CENTER);\n  }\n}\n\npublic class BoxLayoutExample5 extends JFrame\n{\n  public BoxLayoutExample5()\n  {\n    setDefaultCloseOperation(EXIT_ON_CLOSE);\n    setTitle(&quot;BoxLayout&quot;);\n    Container contentPane = getContentPane();\n    contentPane.add( new BoxLayoutExamplePanel() );\n  }\n  \n  public static void main(String&#x5B;] args)\n  {\n    JFrame frame = new BoxLayoutExample5();\n    frame.setSize(300, 200);\n    frame.setVisible(true);\n  }\n}\n\n<\/pre><\/div>\n\n\n<p class=\"wp-block-paragraph\">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\/BoxLayoutExample5.gif\" alt=\"\" class=\"wp-image-1134\"\/><\/figure><\/div>\n\n\n\n<div style=\"height:21px\" aria-hidden=\"true\" class=\"wp-block-spacer\"><\/div>\n\n\n\n<p class=\"wp-block-paragraph\">In other words, a <em>rigid area<\/em> is way of inserting both vertical and horizontal space.<\/p>\n\n\n\n<h4 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Example_6\"><\/span>Example 6<span class=\"ez-toc-section-end\"><\/span><\/h4>\n\n\n\n<p class=\"wp-block-paragraph\">Let&#8217;s say that we want to move the <strong>OK<\/strong> and <strong>Cancel<\/strong> buttons to the right.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">We can do this using&nbsp;<strong><em>glue<\/em><\/strong>:<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: java; auto-links: false; highlight: [39,43]; title: ; quick-code: false; notranslate\" title=\"\">\npackage swingExamples;\n\nimport java.awt.BorderLayout;\nimport java.awt.Container;\nimport java.awt.Dimension;\nimport javax.swing.Box;\nimport javax.swing.JButton;\nimport javax.swing.JFrame;\nimport javax.swing.JLabel;\nimport javax.swing.JPanel;\nimport javax.swing.JTextField;\n\nclass BoxLayoutExamplePanel extends JPanel\n{\n  public BoxLayoutExamplePanel()\n  {\n    setLayout( new BorderLayout() );\n    \n    \/\/ Create a horizontal box &amp; populate it\n    Box hbox1 = Box.createHorizontalBox();\n    hbox1.add( new JLabel(&quot;Name:&quot;) );\n    hbox1.add( Box.createHorizontalStrut(10) );\n    JTextField nameTextField = new JTextField(10);\n    nameTextField.setMaximumSize( \n        nameTextField.getPreferredSize() );\n    hbox1.add(nameTextField);\n    \n    \/\/ Create another horizontal box &amp; populate it\n    Box hbox2 = Box.createHorizontalBox();\n    hbox2.add( new JLabel(&quot;Password:&quot;) );\n    hbox2.add( Box.createHorizontalStrut(10) );\n    JTextField passwordTextField = new JTextField(10);\n    passwordTextField.setMaximumSize( \n        passwordTextField.getPreferredSize() );\n    hbox2.add(passwordTextField);\n    \n    \/\/ Create yet another horizontal box &amp; populate it\n    Box hbox3 = Box.createHorizontalBox();\n    hbox3.add( Box.createGlue() );\n    hbox3.add( new JButton(&quot;OK&quot;) );\n    hbox3.add( Box.createHorizontalStrut(10) );\n    hbox3.add( new JButton(&quot;Cancel&quot;) );\n    hbox3.add( Box.createHorizontalStrut(5) );\n    \n    \/\/ Now, create a vertical box, &amp; \n    \/\/ add the horizontal boxes to it.\n    Box vbox = Box.createVerticalBox();\n    vbox.add(hbox1);\n    vbox.add(hbox2);\n    vbox.add( Box.createRigidArea( \n        new Dimension(10, 80) ) );\n    vbox.add(hbox3);\n    \n    \/\/ Finally, add the vertical box to the \n    \/\/ center of the panel&#039;s border layout.\n    add(vbox, BorderLayout.CENTER);\n  }\n}\n\npublic class BoxLayoutExample6 extends JFrame\n{\n  public BoxLayoutExample6()\n  {\n    setDefaultCloseOperation(EXIT_ON_CLOSE);\n    setTitle(&quot;BoxLayout&quot;);\n    Container contentPane = getContentPane();\n    contentPane.add( new BoxLayoutExamplePanel() );\n  }\n  \n  public static void main(String&#x5B;] args)\n  {\n    JFrame frame = new BoxLayoutExample6();\n    frame.setSize(300, 200);\n    frame.setVisible(true);\n  }\n}\n<\/pre><\/div>\n\n\n<p class=\"wp-block-paragraph\">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\/BoxLayoutExample6.gif\" alt=\"\" class=\"wp-image-1138\"\/><\/figure><\/div>\n\n\n\n<div style=\"height:25px\" aria-hidden=\"true\" class=\"wp-block-spacer\"><\/div>\n\n\n\n<p class=\"wp-block-paragraph\">The &#8220;glue&#8221;, placed between two components, has the effect of pushing components apart.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Note that I added a <em>horizontal strut<\/em> after the <strong>Cancel<\/strong> button to prevent it from being pushed all the way to the border of the panel.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><\/p>\n\n\n\n<h3 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"GridBagLayout\"><\/span>GridBagLayout<span class=\"ez-toc-section-end\"><\/span><\/h3>\n\n\n\n<p class=\"wp-block-paragraph\"><code><strong>GridBagLayout<\/strong><\/code>&nbsp;is by far the most difficult to use of the standard layout managers.&nbsp; While it is very flexible, it is incredibly painful to use, and very picky &#8212; the smallest mistake can mess things up royally!.&nbsp;&nbsp;<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">In order to use a&nbsp;<code>GridBagLayout<\/code>, you also must use a <code><strong>GridBagConstraints<\/strong><\/code>.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Here&#8217;s an example of the use of&nbsp;<code><strong>GridBagLayout<\/strong><\/code>:<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: java; auto-links: false; highlight: [7,8,28,29,30,31,32,33,34,35,36,37,38,39,40,41,42,43,44,45,46,47,48,49,50,51,52,53,54,55,56,57,58,59,60,61,62,63,64,65,66,67,68,69,70,71,72,73,74,75]; title: ; quick-code: false; notranslate\" title=\"\">\npackage swingExamples;\n\nimport java.awt.Color;\nimport java.awt.Component;\nimport java.awt.Container;\nimport java.awt.Font;\nimport java.awt.GridBagConstraints;\nimport java.awt.GridBagLayout;\n\nimport java.awt.event.ActionEvent;\nimport java.awt.event.ActionListener;\n\nimport javax.swing.JCheckBox;\nimport javax.swing.JFrame;\nimport javax.swing.JLabel;\nimport javax.swing.JList;\nimport javax.swing.JPanel;\nimport javax.swing.JTextField;\n\nimport javax.swing.event.ListSelectionEvent;\nimport javax.swing.event.ListSelectionListener;\n\nclass FontLayoutPanel extends JPanel \n    implements ActionListener, ListSelectionListener\n{\n  public FontLayoutPanel()\n  {\n    setLayout(new GridBagLayout());\n    setBackground(Color.pink);\n    GridBagConstraints gbc = new GridBagConstraints();\n    \n    m_fontList.setSelectedIndex(0);\n    m_fontList.addListSelectionListener(this);\n    gbc.fill = GridBagConstraints.BOTH;\n    gbc.weightx = 0.0;\n    gbc.weighty = 1.0;\n    add(m_fontList, gbc, 0, 0, 1, 3);\n    \n    m_bold.addActionListener(this);\n    m_bold.setBackground(Color.green);\n    gbc.weightx = 1.0;\n    gbc.fill = GridBagConstraints.NONE;\n    gbc.anchor = GridBagConstraints.CENTER;\n    add(m_bold, gbc, 1, 0, 2, 1);\n    \n    m_italic.addActionListener(this);\n    m_italic.setBackground(Color.cyan);\n    add(m_italic, gbc, 1, 1, 2, 1);\n    \n    m_sizeLabel.setBackground(Color.yellow);\n    add(m_sizeLabel, gbc, 1, 2, 1, 1);\n    \n    m_size.addActionListener(this);\n    gbc.fill = GridBagConstraints.HORIZONTAL;\n    add(m_size, gbc, 2, 2, 1, 1);\n    \n    m_sample.setBackground(Color.magenta);\n    m_sample.setEditable(false);\n    m_sample.setText(&quot;The quick brown fox&quot;);\n    gbc.anchor = GridBagConstraints.SOUTH;\n    gbc.weighty = 0.0;\n    add(m_sample, gbc, 0, 3, 4, 1);\n  }\n  \n  private void add(Component comp, \n                   GridBagConstraints gbc,\n                   int x, int y, \n                   int width, int height)\n  {\n    gbc.gridx = x;\n    gbc.gridy = y;\n    gbc.gridwidth = width;\n    gbc.gridheight = height;\n    add(comp, gbc);\n  }\n  \n  public void actionPerformed(ActionEvent evt)\n  {\n    updateFont();\n  }\n  \n  public void valueChanged(ListSelectionEvent evt)\n  {\n    updateFont();\n  }\n  \n  private void updateFont()\n  {\n    int style = 0;\n    if (m_bold.isSelected())\n    {\n      style = Font.BOLD;\n    }\n    if (m_italic.isSelected())\n    {\n      style += Font.ITALIC;\n    }\n    Font font = new Font( \n        (String) m_fontList.getSelectedValue(),\n        style,\n        Integer.parseInt(m_size.getText())\n        );\n    m_sample.setFont(font);\n    repaint();\n  }\n  \n  \/\/\/\/\/\/ Private data \/\/\/\/\/\/\n  private static final String&#x5B;] m_fonts =\n  {\n    &quot;Serif&quot;, &quot;SansSerif&quot;, &quot;Monospaced&quot;, \n    &quot;Dialog&quot;, &quot;DialogInput&quot;\n  };\n  private JList m_fontList = new JList(m_fonts);\n  private JCheckBox m_bold = new JCheckBox(&quot;Bold&quot;);\n  private JCheckBox m_italic = new JCheckBox(&quot;Italic&quot;);\n  private JLabel m_sizeLabel = new JLabel(&quot;Size: &quot;);\n  private JTextField m_size = new JTextField(&quot;10&quot;, 2);\n  private JTextField m_sample = new JTextField();\n}\n\nclass FontLayoutFrame extends JFrame\n{\n  public FontLayoutFrame()\n  {\n    setTitle(&quot;FontLayout&quot;);\n    setSize(300, 200);\n    setDefaultCloseOperation(EXIT_ON_CLOSE);\n    Container contentPane = getContentPane();\n    contentPane.add( new FontLayoutPanel() );\n  }\n}\n\npublic class GridBagLayoutExample\n{\n  public static void main(String&#x5B;] args)\n  {\n    FontLayoutFrame frame = new FontLayoutFrame();\n    frame.setVisible(true);\n  }\n}\n<\/pre><\/div>\n\n\n<p class=\"wp-block-paragraph\">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\/FontLayout.gif\" alt=\"\" class=\"wp-image-1142\"\/><\/figure><\/div>\n\n\n\n<div style=\"height:19px\" aria-hidden=\"true\" class=\"wp-block-spacer\"><\/div>\n\n\n\n<p class=\"wp-block-paragraph\">Note that the (rather garish!) colors are meant to show you the boundaries of the various components.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"SpringLayout\"><\/span>SpringLayout<span class=\"ez-toc-section-end\"><\/span><\/h3>\n\n\n\n<p class=\"wp-block-paragraph\"><code><strong>SpringLayout<\/strong><\/code>&nbsp;is the latest attempt by JavaSoft to produce a layout manager that can compete with&nbsp;<code><strong>GridBagLayout<\/strong><\/code>&nbsp;for flexibility, but which is supposed to be easier and more intuitive to use.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Here&#8217;s an example, from the textbook (slightly modified by me):<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: java; auto-links: false; highlight: [20,21,35,86,87,88,89,90,91,92,93,94,95,96,97,98,99,100,101,102,103,104,105,106,107,108,109,110,111,112,113,114,115,116,117,118,119,120,121,122,123,124,125,126,127,128,129,130,131,132,133,134,135,136,137,138,139,140,141,142,143,144,145,146,147,148,149,150,151,152,153,154,155,156,157,158,159,160,161,162,163,164,165,166,167,168,169,170,171,172,173,174,175,176,177,178,179,180,181,182]; title: ; quick-code: false; notranslate\" title=\"\">\npackage swingExamples;\n\n\/**\n * A class to show an example of a SpringLayout.\n *\n * @version 1.01 2004-05-06\n * @author Cay Horstmann, modified by Bryan Higgs\n *\/\n\nimport java.awt.Font;\nimport java.awt.event.ActionEvent;\nimport java.awt.event.ActionListener;\nimport javax.swing.BorderFactory;\nimport javax.swing.JCheckBox;\nimport javax.swing.JComboBox;\nimport javax.swing.JFrame;\nimport javax.swing.JLabel;\nimport javax.swing.JPanel;\nimport javax.swing.JTextArea;\nimport javax.swing.Spring;\nimport javax.swing.SpringLayout;\n\n\/**\n * A frame that uses a spring layout to arrange font\n * selection components.\n *\/\nclass FontDialogFrame extends JFrame\n{\n  public FontDialogFrame()\n  {\n    setTitle(&quot;FontDialog&quot;);\n    setSize(DEFAULT_WIDTH, DEFAULT_HEIGHT);\n    \n    JPanel panel = new JPanel();\n    SpringLayout layout = new SpringLayout();\n    panel.setLayout(layout);\n    \n    ActionListener listener = new FontAction();\n    \n    \/\/ construct components\n    JLabel faceLabel = new JLabel(&quot;Font Face: &quot;);\n    \n    face = new JComboBox(\n        new String&#x5B;]\n        {\n          &quot;Serif&quot;, &quot;SansSerif&quot;, &quot;Monospaced&quot;,\n          &quot;Dialog&quot;, &quot;DialogInput&quot;\n        }\n    );\n    face.addActionListener(listener);\n    \n    JLabel sizeLabel = new JLabel(&quot;Size: &quot;);\n    \n    size = new JComboBox(\n        new String&#x5B;]\n        {\n          &quot;8&quot;, &quot;10&quot;, &quot;12&quot;, &quot;15&quot;, &quot;18&quot;, \n          &quot;24&quot;, &quot;36&quot;, &quot;48&quot;\n        }\n    );\n    \n    size.addActionListener(listener);\n    \n    bold = new JCheckBox(&quot;Bold&quot;);\n    bold.addActionListener(listener);\n    \n    italic = new JCheckBox(&quot;Italic&quot;);\n    italic.addActionListener(listener);\n    \n    sample = new JTextArea();\n    sample.setText(\n        &quot;The quick brown fox jumps over the lazy dog&quot;);\n    sample.setEditable(false);\n    sample.setLineWrap(true);\n    sample.setBorder(\n        BorderFactory.createEtchedBorder());\n    \n    panel.add(faceLabel);\n    panel.add(sizeLabel);\n    panel.add(face);\n    panel.add(size);\n    panel.add(bold);\n    panel.add(italic);\n    panel.add(sample);\n    \n    \/\/ add springs to lay out components\n    Spring strut = Spring.constant(10);\n    \n    Spring labelsEast = Spring.sum(strut,\n        Spring.max(\n        layout.getConstraints(faceLabel).getWidth(),\n        layout.getConstraints(sizeLabel).getWidth()));\n    \n    layout.putConstraint(\n        SpringLayout.EAST, \n        faceLabel, labelsEast, SpringLayout.WEST, panel);\n    layout.putConstraint(\n        SpringLayout.EAST, \n        sizeLabel, labelsEast, SpringLayout.WEST, panel);\n    \n    layout.putConstraint(\n        SpringLayout.NORTH, \n        faceLabel, strut, SpringLayout.NORTH, panel);\n    layout.putConstraint(\n        SpringLayout.NORTH, \n        face, strut, SpringLayout.NORTH, panel);\n    \n    Spring secondRowNorth = \n        Spring.sum(strut,\n                   Spring.max(\n                      layout.getConstraint(\n                          SpringLayout.SOUTH, faceLabel),\n                      layout.getConstraint(\n                          SpringLayout.SOUTH, face)\n                      )\n                   );\n    \n    layout.putConstraint(\n        SpringLayout.NORTH, \n        sizeLabel, secondRowNorth, SpringLayout.NORTH, panel);\n    layout.putConstraint(\n        SpringLayout.NORTH, \n        size, secondRowNorth, SpringLayout.NORTH, panel);\n    \n    layout.putConstraint(\n        SpringLayout.WEST, \n        face, strut, SpringLayout.EAST, faceLabel);\n    layout.putConstraint(\n        SpringLayout.WEST, \n        size, strut, SpringLayout.EAST, sizeLabel);\n    \n    layout.putConstraint(\n        SpringLayout.WEST, \n        bold, strut, SpringLayout.WEST, panel);\n    layout.putConstraint(\n        SpringLayout.WEST, \n        italic, strut, SpringLayout.WEST, panel);\n    \n    Spring s = Spring.constant(10, 10000, 10000);\n    \n    Spring thirdRowNorth = \n        Spring.sum(s,\n                   Spring.max(\n                      layout.getConstraint(\n                        SpringLayout.SOUTH, sizeLabel),\n                      layout.getConstraint(\n                        SpringLayout.SOUTH, size)\n                      )\n                  );\n    \n    layout.putConstraint(\n        SpringLayout.NORTH, \n        bold, thirdRowNorth, SpringLayout.NORTH, panel);\n    layout.putConstraint(\n        SpringLayout.NORTH, \n        italic, s, SpringLayout.SOUTH, bold);\n    layout.putConstraint(\n        SpringLayout.SOUTH, \n        panel, s, SpringLayout.SOUTH, italic);\n    \n    Spring secondColumnWest = \n        Spring.sum(strut,\n                   Spring.max(\n                      layout.getConstraint(\n                        SpringLayout.EAST, face),\n                      layout.getConstraint(\n                        SpringLayout.EAST, size)\n                      )\n                   );\n    \n    layout.putConstraint(\n        SpringLayout.WEST, \n        sample, secondColumnWest, SpringLayout.WEST, panel);\n    layout.putConstraint(\n        SpringLayout.SOUTH, \n        sample, Spring.minus(strut), SpringLayout.SOUTH, panel);\n    layout.putConstraint(\n        SpringLayout.NORTH, \n        sample, strut, SpringLayout.NORTH, panel);\n    layout.putConstraint(\n        SpringLayout.EAST, \n        panel, strut, SpringLayout.EAST, sample);\n    \n    add(panel);\n  }\n  \n  \/\/\/\/\/ Private data \/\/\/\/\n  private static final int DEFAULT_WIDTH = 400;\n  private static final int DEFAULT_HEIGHT = 200;\n  \n  private JComboBox face;\n  private JComboBox size;\n  private JCheckBox bold;\n  private JCheckBox italic;\n  private JTextArea sample;\n  \n  \/**\n   * An action listener that changes the font of the\n   * sample text.\n   *\/\n  private class FontAction implements ActionListener\n  {\n    public void actionPerformed(ActionEvent event)\n    {\n      String fontFace = (String) face.getSelectedItem();\n      int fontStyle = (bold.isSelected() ? Font.BOLD : 0)\n      + (italic.isSelected() ? Font.ITALIC : 0);\n      int fontSize = Integer.parseInt(\n                        (String) size.getSelectedItem());\n      Font font = new Font(fontFace, fontStyle, fontSize);\n      sample.setFont(font);\n      sample.repaint();\n    }\n  }\n}\n\npublic class SpringLayoutExample\n{\n  public static void main(String&#x5B;] args)\n  {\n    FontDialogFrame frame = new FontDialogFrame();\n    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);\n    frame.setVisible(true);\n  }\n}\n\n<\/pre><\/div>\n\n\n<p class=\"wp-block-paragraph\">which produces the following output on my Microsoft Windows machine:<\/p>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"alignleft size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"400\" height=\"200\" src=\"https:\/\/bhiggs.x10hosting.com\/PracticalJavaProgramming\/wp-content\/uploads\/2021\/01\/Spring1.jpg\" alt=\"\" class=\"wp-image-1147\" srcset=\"https:\/\/bhiggs.x10hosting.com\/PracticalJavaProgramming\/wp-content\/uploads\/2021\/01\/Spring1.jpg 400w, https:\/\/bhiggs.x10hosting.com\/PracticalJavaProgramming\/wp-content\/uploads\/2021\/01\/Spring1-300x150.jpg 300w\" sizes=\"(max-width: 400px) 100vw, 400px\" \/><\/figure><\/div>\n\n\n\n<div style=\"height:24px\" aria-hidden=\"true\" class=\"wp-block-spacer\"><\/div>\n\n\n\n<p class=\"wp-block-paragraph\">Well, it&#8217;s certainly not simple, is it?<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Here are some more layout managers that you can use. Two recently introduced layout managers are&nbsp;BoxLayout&nbsp;and&nbsp;SpringLayout. GridBagLayout, is often referred to as &#8220;the mother of all layout managers&#8221;.&nbsp; It is probably the most complex of all layout managers.&nbsp; It can do virtually any layout you would like, but not without putting up a good fight.&nbsp; [&hellip;]<\/p>\n","protected":false},"author":2,"featured_media":0,"parent":71,"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-1114","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":"Here are some more layout managers that you can use. Two recently introduced layout managers are&nbsp;BoxLayout&nbsp;and&nbsp;SpringLayout. GridBagLayout, is often referred to as &#8220;the mother of all layout managers&#8221;.&nbsp; It is probably the most complex of all layout managers.&nbsp; It can do virtually any layout you would like, but not without putting up a good fight.&nbsp;&hellip;","_links":{"self":[{"href":"https:\/\/bhiggs.x10hosting.com\/PracticalJavaProgramming\/wp-json\/wp\/v2\/pages\/1114","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=1114"}],"version-history":[{"count":20,"href":"https:\/\/bhiggs.x10hosting.com\/PracticalJavaProgramming\/wp-json\/wp\/v2\/pages\/1114\/revisions"}],"predecessor-version":[{"id":1151,"href":"https:\/\/bhiggs.x10hosting.com\/PracticalJavaProgramming\/wp-json\/wp\/v2\/pages\/1114\/revisions\/1151"}],"up":[{"embeddable":true,"href":"https:\/\/bhiggs.x10hosting.com\/PracticalJavaProgramming\/wp-json\/wp\/v2\/pages\/71"}],"wp:attachment":[{"href":"https:\/\/bhiggs.x10hosting.com\/PracticalJavaProgramming\/wp-json\/wp\/v2\/media?parent=1114"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}