{"id":26789,"date":"2021-05-01T23:10:05","date_gmt":"2021-05-02T03:10:05","guid":{"rendered":"http:\/\/bangla.salearningschool.com\/recent-posts\/placement-of-buttons-in-a-boxlayout-using-rigid-areas-struts-and-glue-programming-code-examples-java-j2ee-j2me-layout-managers\/"},"modified":"2022-05-10T20:08:40","modified_gmt":"2022-05-11T00:08:40","slug":"placement-of-buttons-in-a-boxlayout-using-rigid-areas-struts-and-glue-programming-code-examples-java-j2ee-j2me-layout-managers","status":"publish","type":"post","link":"http:\/\/bangla.sitestree.com\/?p=26789","title":{"rendered":"Placement of buttons in a BoxLayout using rigid areas, struts, and glue #Programming Code Examples #Java\/J2EE\/J2ME #Layout Managers"},"content":{"rendered":"<pre>\n###############\nInvisibleComponentTest.java Placement of buttons in a BoxLayout using rigid areas, struts, and glue\n###############\nimport java.awt.*;\nimport javax.swing.*;\nimport javax.swing.border.*;\n\n\/** Example of using rigid areas, struts, and glue to\n *  produce the effect of invisible components.\n *\n ******************\n\npublic class InvisibleComponentTest extends JPanel {\n  Component spacer;\n\n  public InvisibleComponentTest() {\n    setLayout(new BoxLayout(this, BoxLayout.Y_AXIS));\n\n    \/\/ Place a rigid invisible component 25 pixels wide and\n    \/\/ 75 pixels tall between the two buttons\n    JPanel p1= new JPanel();\n    spacer = Box.createRigidArea(new Dimension(20,75));\n    setUpPanel(p1, &quot;Rigid Area - 20x75 pixels&quot;, spacer);\n\n    \/\/ Separate two buttons by a 60-pixel horizontal strut\n    JPanel p2= new JPanel();\n    spacer = Box.createHorizontalStrut(60);\n    setUpPanel(p2, &quot;Horizontal Strut - 60 pixels&quot;, spacer);\n\n    \/\/ Horizontal glue in FlowLayout - not useful\n    JPanel p3= new JPanel();\n    spacer = Box.createHorizontalGlue();\n    setUpPanel(p3, &quot;Horizontal Glue - FlowLayout&quot;, spacer);\n\n    \/\/ Add glue to fill all remaining horizontal space between\n    \/\/ the two buttons. Glue not supported by default FlowLayout\n    \/\/ of JPanel.  Change layout of JPanel to BoxLayout.\n    JPanel p4= new JPanel();\n    p4.setLayout(new BoxLayout(p4,BoxLayout.X_AXIS));\n    spacer = Box.createHorizontalGlue();\n    setUpPanel(p4, &quot;Horizontal Glue - BoxLayout&quot;, spacer);\n\n    add(p1);\n    add(p2);\n    add(p3);\n    add(p4);\n  }\n\n  \/\/ Helper to set the border and add components\n  private void setUpPanel(JPanel p, String title,\n                          Component spacer) {\n    p.setBorder(BorderFactory.createTitledBorder(\n                       BorderFactory.createEtchedBorder(),title,\n                       TitledBorder.TOP,TitledBorder.CENTER));\n    p.setBackground(Color.white);\n    p.add(new JButton(&quot;Left&quot;));\n    p.add(spacer);\n    p.add(new JButton(&quot;Right&quot;));\n  }\n\n  public static void main(String[] args) {\n    String title = &quot;Using Invisible Components&quot;;\n    WindowUtilities.setNativeLookAndFeel();\n    WindowUtilities.openInJFrame(new InvisibleComponentTest(),\n                                 350, 325, title);\n  }\n}\n<\/pre>\n<p>Note: Brought from our old site: http:\/\/www.salearningschool.com\/example_codes\/ on Jan 2nd, 2017 From: http:\/\/sitestree.com\/?p=10354<br \/> Categories:Programming Code Examples, Java\/J2EE\/J2ME, Layout Managers<br \/>Tags:Java\/J2EE\/J2MELayout Managers<br \/> Post Data:2017-01-02 16:04:35<\/p>\n<p>\t\tShop Online: <a href='https:\/\/www.ShopForSoul.com\/' target='new' rel=\"noopener\">https:\/\/www.ShopForSoul.com\/<\/a><br \/>\n\t\t(Big Data, Cloud, Security, Machine Learning): Courses: <a href='http:\/\/Training.SitesTree.com' target='new' rel=\"noopener\"> http:\/\/Training.SitesTree.com<\/a><br \/>\n\t\tIn Bengali: <a href='http:\/\/Bangla.SaLearningSchool.com' target='new' rel=\"noopener\">http:\/\/Bangla.SaLearningSchool.com<\/a><br \/>\n\t\t<a href='http:\/\/SitesTree.com' target='new' rel=\"noopener\">http:\/\/SitesTree.com<\/a><br \/>\n\t\t8112223 Canada Inc.\/JustEtc: <a href='http:\/\/JustEtc.net' target='new' rel=\"noopener\">http:\/\/JustEtc.net (Software\/Web\/Mobile\/Big-Data\/Machine Learning) <\/a><br \/>\n\t\tShop Online: <a href='https:\/\/www.ShopForSoul.com'> https:\/\/www.ShopForSoul.com\/<\/a><br \/>\n\t\tMedium: <a href='https:\/\/medium.com\/@SayedAhmedCanada' target='new' rel=\"noopener\"> https:\/\/medium.com\/@SayedAhmedCanada <\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>############### InvisibleComponentTest.java Placement of buttons in a BoxLayout using rigid areas, struts, and glue ############### import java.awt.*; import javax.swing.*; import javax.swing.border.*; \/** Example of using rigid areas, struts, and glue to * produce the effect of invisible components. * ****************** public class InvisibleComponentTest extends JPanel { Component spacer; public InvisibleComponentTest() { setLayout(new BoxLayout(this, BoxLayout.Y_AXIS)); \/\/ &hellip; <\/p>\n<p><a class=\"more-link btn\" href=\"http:\/\/bangla.sitestree.com\/?p=26789\">Continue reading<\/a><\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"_jetpack_feature_clip_id":0,"_jetpack_memberships_contains_paid_content":false,"footnotes":"","jetpack_post_was_ever_published":false},"categories":[1917,1955],"tags":[],"class_list":["post-26789","post","type-post","status-publish","format-standard","hentry","category-fromsitestree-com","category-struts","item-wrap"],"jetpack_featured_media_url":"","jetpack_sharing_enabled":true,"jetpack-related-posts":[{"id":10321,"url":"http:\/\/bangla.sitestree.com\/?p=10321","url_meta":{"origin":26789,"position":0},"title":"Placement of buttons in a BoxLayout using rigid areas, struts, and glue","author":"Sayed","date":"August 26, 2015","format":false,"excerpt":"############### InvisibleComponentTest.java Placement of buttons in a BoxLayout using rigid areas, struts, and glue ############### import java.awt.*; import javax.swing.*; import javax.swing.border.*; \/** Example of using rigid areas, struts, and glue to \u00a0*\u00a0 produce the effect of invisible components. \u00a0* \u00a0****************** public class InvisibleComponentTest extends JPanel { \u00a0 Component spacer; \u00a0\u2026","rel":"","context":"In &quot;Code . Programming Samples . \u09aa\u09cd\u09b0\u09cb\u0997\u09cd\u09b0\u09be\u09ae \u0989\u09a6\u09be\u09b9\u09b0\u09a8&quot;","block_context":{"text":"Code . Programming Samples . \u09aa\u09cd\u09b0\u09cb\u0997\u09cd\u09b0\u09be\u09ae \u0989\u09a6\u09be\u09b9\u09b0\u09a8","link":"http:\/\/bangla.sitestree.com\/?cat=1417"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":10225,"url":"http:\/\/bangla.sitestree.com\/?p=10225","url_meta":{"origin":26789,"position":1},"title":"A JPanel that displays six radio buttons with labels.","author":"","date":"August 25, 2015","format":false,"excerpt":"A JPanel that displays six radio buttons with labels. import java.awt.*; import javax.swing.*; \/** A JPanel that displays six JRadioButtons. \u00a0* \u00a0*. \u00a0*\/ public class SixChoicePanel extends JPanel { \u00a0 public SixChoicePanel(String title, String[] buttonLabels) { \u00a0\u00a0\u00a0 super(new GridLayout(3, 2)); \u00a0\u00a0\u00a0 setBackground(Color.lightGray); \u00a0\u00a0\u00a0 setBorder(BorderFactory.createTitledBorder(title)); \u00a0\u00a0\u00a0 ButtonGroup group = new ButtonGroup();\u2026","rel":"","context":"In &quot;Code . Programming Samples . \u09aa\u09cd\u09b0\u09cb\u0997\u09cd\u09b0\u09be\u09ae \u0989\u09a6\u09be\u09b9\u09b0\u09a8&quot;","block_context":{"text":"Code . Programming Samples . \u09aa\u09cd\u09b0\u09cb\u0997\u09cd\u09b0\u09be\u09ae \u0989\u09a6\u09be\u09b9\u09b0\u09a8","link":"http:\/\/bangla.sitestree.com\/?cat=1417"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":26914,"url":"http:\/\/bangla.sitestree.com\/?p=26914","url_meta":{"origin":26789,"position":2},"title":"A JPanel that displays six radio buttons with labels. #Programming Code Examples #Java\/J2EE\/J2ME #Basic Swing","author":"Author-Check- Article-or-Video","date":"May 5, 2021","format":false,"excerpt":"A JPanel that displays six radio buttons with labels. import java.awt.*; import javax.swing.*; \/** A JPanel that displays six JRadioButtons. * *. *\/ public class SixChoicePanel extends JPanel { public SixChoicePanel(String title, String[] buttonLabels) { super(new GridLayout(3, 2)); setBackground(Color.lightGray); setBorder(BorderFactory.createTitledBorder(title)); ButtonGroup group = new ButtonGroup(); JRadioButton option; int halfLength =\u2026","rel":"","context":"In &quot;FromSitesTree.com&quot;","block_context":{"text":"FromSitesTree.com","link":"http:\/\/bangla.sitestree.com\/?cat=1917"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":10317,"url":"http:\/\/bangla.sitestree.com\/?p=10317","url_meta":{"origin":26789,"position":3},"title":"Layout of complicated GUI by taking advantage of nested containers","author":"","date":"August 26, 2015","format":false,"excerpt":"################# NestedLayout.java Layout of complicated GUI by taking advantage of nested containers. Uses WindowUtilities.java and ExitListener.java. ################## import java.awt.*; import java.awt.event.*; import java.util.*; import javax.swing.*; import javax.swing.border.*; import javax.swing.event.*; \/** An example demonstrating the use of nested containers \u00a0*\u00a0 to lay out the components. See GridBagTest.java for \u00a0*\u00a0 implementation by\u2026","rel":"","context":"In &quot;Code . Programming Samples . \u09aa\u09cd\u09b0\u09cb\u0997\u09cd\u09b0\u09be\u09ae \u0989\u09a6\u09be\u09b9\u09b0\u09a8&quot;","block_context":{"text":"Code . Programming Samples . \u09aa\u09cd\u09b0\u09cb\u0997\u09cd\u09b0\u09be\u09ae \u0989\u09a6\u09be\u09b9\u09b0\u09a8","link":"http:\/\/bangla.sitestree.com\/?cat=1417"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":26785,"url":"http:\/\/bangla.sitestree.com\/?p=26785","url_meta":{"origin":26789,"position":4},"title":"Layout of complicated GUI by taking advantage of nested containers #Programming Code Examples #Java\/J2EE\/J2ME #Layout Managers","author":"Author-Check- Article-or-Video","date":"May 1, 2021","format":false,"excerpt":"################# NestedLayout.java Layout of complicated GUI by taking advantage of nested containers. Uses WindowUtilities.java and ExitListener.java. ################## import java.awt.*; import java.awt.event.*; import java.util.*; import javax.swing.*; import javax.swing.border.*; import javax.swing.event.*; \/** An example demonstrating the use of nested containers * to lay out the components. See GridBagTest.java for * implementation by\u2026","rel":"","context":"In &quot;FromSitesTree.com&quot;","block_context":{"text":"FromSitesTree.com","link":"http:\/\/bangla.sitestree.com\/?cat=1917"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":26948,"url":"http:\/\/bangla.sitestree.com\/?p=26948","url_meta":{"origin":26789,"position":5},"title":"Creates three radio buttons and illustrates handling #Programming Code Examples #Java\/J2EE\/J2ME #Basic Swing","author":"Author-Check- Article-or-Video","date":"May 6, 2021","format":false,"excerpt":"JRadioButtonTest.java Creates three radio buttons and illustrates handling ItemEvents in response to selecting a radio button. import javax.swing.JRadioButton; import javax.swing.ButtonGroup; import java.awt.*; import java.awt.event.*; import javax.swing.*; \/** *\/ public class JRadioButtonTest extends JPanel implements ItemListener { public JRadioButtonTest() { String[] labels = {\"Java Swing\",\"Java Servlets\", \"JavaServer Pages\"}; JRadioButton[] buttons =\u2026","rel":"","context":"In &quot;FromSitesTree.com&quot;","block_context":{"text":"FromSitesTree.com","link":"http:\/\/bangla.sitestree.com\/?cat=1917"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]}],"_links":{"self":[{"href":"http:\/\/bangla.sitestree.com\/index.php?rest_route=\/wp\/v2\/posts\/26789","targetHints":{"allow":["GET"]}}],"collection":[{"href":"http:\/\/bangla.sitestree.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/bangla.sitestree.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/bangla.sitestree.com\/index.php?rest_route=\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"http:\/\/bangla.sitestree.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=26789"}],"version-history":[{"count":1,"href":"http:\/\/bangla.sitestree.com\/index.php?rest_route=\/wp\/v2\/posts\/26789\/revisions"}],"predecessor-version":[{"id":74579,"href":"http:\/\/bangla.sitestree.com\/index.php?rest_route=\/wp\/v2\/posts\/26789\/revisions\/74579"}],"wp:attachment":[{"href":"http:\/\/bangla.sitestree.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=26789"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/bangla.sitestree.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=26789"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/bangla.sitestree.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=26789"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}