{"id":26910,"date":"2021-05-05T23:10:05","date_gmt":"2021-05-06T03:10:05","guid":{"rendered":"http:\/\/bangla.salearningschool.com\/recent-posts\/a-simple-example-that-illustrates-creating-panels-programming-code-examples-java-j2ee-j2me-basic-swing\/"},"modified":"2021-05-05T23:10:05","modified_gmt":"2021-05-06T03:10:05","slug":"a-simple-example-that-illustrates-creating-panels-programming-code-examples-java-j2ee-j2me-basic-swing","status":"publish","type":"post","link":"http:\/\/bangla.sitestree.com\/?p=26910","title":{"rendered":"A simple example that illustrates creating panels #Programming Code Examples #Java\/J2EE\/J2ME #Basic Swing"},"content":{"rendered":"<pre>\nA simple example that illustrates creating panels. In Swing, a JPanel can contain custom borders. Typically, utility methods in the BorderFactory class are used to create a border for the panel. Uses the following class:\n\n    * SixChoicePanel.java A JPanel that displays six radio buttons with labels.\nimport java.awt.*;\nimport javax.swing.*;\n\n\/** Simple example illustrating the use of JPanels, especially\n *  the ability to add Borders.\n *\n  *\/\n\npublic class JPanels extends JFrame {\n  public static void main(String[] args) {\n    new JPanels();\n  }\n\n  public JPanels() {\n    super(&quot;Using JPanels with Borders&quot;);\n    WindowUtilities.setNativeLookAndFeel();\n    addWindowListener(new ExitListener());\n    Container content = getContentPane();\n    content.setBackground(Color.lightGray);\n    JPanel controlArea = new JPanel(new GridLayout(3, 1));\n    String[] colors = { &quot;Red&quot;, &quot;Green&quot;, &quot;Blue&quot;,\n                        &quot;Black&quot;, &quot;White&quot;, &quot;Gray&quot; };\n    controlArea.add(new SixChoicePanel(&quot;Color&quot;, colors));\n    String[] thicknesses = { &quot;1&quot;, &quot;2&quot;, &quot;3&quot;, &quot;4&quot;, &quot;5&quot;, &quot;6&quot; };\n    controlArea.add(new SixChoicePanel(&quot;Line Thickness&quot;,\n                                       thicknesses));\n    String[] fontSizes = { &quot;10&quot;, &quot;12&quot;, &quot;14&quot;, &quot;18&quot;, &quot;24&quot;, &quot;36&quot; };\n    controlArea.add(new SixChoicePanel(&quot;Font Size&quot;,\n                                       fontSizes));\n    content.add(controlArea, BorderLayout.EAST);\n    JPanel drawingArea = new JPanel();\n    \/\/ Preferred height is irrelevant, since using WEST region.\n    drawingArea.setPreferredSize(new Dimension(400, 0));\n    drawingArea.setBorder\n               (BorderFactory.createLineBorder (Color.blue, 2));\n    drawingArea.setBackground(Color.white);\n    content.add(drawingArea, BorderLayout.WEST);\n    pack();\n    setVisible(true);\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=10307<br \/> Categories:Programming Code Examples, Java\/J2EE\/J2ME, Basic Swing<br \/>Tags:Java\/J2EE\/J2MEBasic Swing<br \/> Post Data:2017-01-02 16:04:31<\/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>A simple example that illustrates creating panels. In Swing, a JPanel can contain custom borders. Typically, utility methods in the BorderFactory class are used to create a border for the panel. Uses the following class: * SixChoicePanel.java A JPanel that displays six radio buttons with labels. import java.awt.*; import javax.swing.*; \/** Simple example illustrating the &hellip; <\/p>\n<p><a class=\"more-link btn\" href=\"http:\/\/bangla.sitestree.com\/?p=26910\">Continue reading<\/a><\/p>\n","protected":false},"author":8,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_jetpack_memberships_contains_paid_content":false,"footnotes":""},"categories":[1917],"tags":[],"class_list":["post-26910","post","type-post","status-publish","format-standard","hentry","category-fromsitestree-com","item-wrap"],"jetpack_featured_media_url":"","jetpack_sharing_enabled":true,"jetpack-related-posts":[{"id":10214,"url":"http:\/\/bangla.sitestree.com\/?p=10214","url_meta":{"origin":26910,"position":0},"title":"Basic Swing Details","author":"","date":"August 25, 2015","format":false,"excerpt":"WindowUtilities.java Utility class that simplifies creating a window and setting the look and feel. ExitListener.java A WindowListener with support to close the window. JAppletExample.java A simple applet (JApplet) created in Swing. Illustrates setting the look and feel, adding components to the content pane, and changing the layout to FlowLayout (default\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":26896,"url":"http:\/\/bangla.sitestree.com\/?p=26896","url_meta":{"origin":26910,"position":1},"title":"Basic Swing Details #Programming Code Examples #Java\/J2EE\/J2ME #Basic Swing","author":"Author-Check- Article-or-Video","date":"May 4, 2021","format":false,"excerpt":"* WindowUtilities.java Utility class that simplifies creating a window and setting the look and feel. * ExitListener.java A WindowListener with support to close the window. * JAppletExample.java A simple applet (JApplet) created in Swing. Illustrates setting the look and feel, adding components to the content pane, and changing the layout\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":26910,"position":2},"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":[]},{"id":10243,"url":"http:\/\/bangla.sitestree.com\/?p=10243","url_meta":{"origin":26910,"position":3},"title":"Creates three radio buttons and illustrates handling","author":"","date":"August 25, 2015","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.*; \/** \u00a0*\/ public class JRadioButtonTest extends JPanel \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 implements ItemListener { \u00a0 public JRadioButtonTest() { \u00a0 \u00a0 \u00a0\u00a0\u00a0 String[] labels = {\"Java Swing\",\"Java Servlets\",\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":26910,"position":4},"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":27194,"url":"http:\/\/bangla.sitestree.com\/?p=27194","url_meta":{"origin":26910,"position":5},"title":"Printing in Java 2 #Programming Code Examples #Java\/J2EE\/J2ME #Advanced Swing","author":"Author-Check- Article-or-Video","date":"May 13, 2021","format":false,"excerpt":"* o PrintExample.java Demonstrates printing a Graphics2D object. import java.awt.*; import javax.swing.*; import java.awt.event.*; import java.awt.print.*; \/** An example of a printable window in Java 1.2. The key point * here is that any component is printable in Java 1.2. * However, you have to be careful to turn off\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\/26910","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\/8"}],"replies":[{"embeddable":true,"href":"http:\/\/bangla.sitestree.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=26910"}],"version-history":[{"count":0,"href":"http:\/\/bangla.sitestree.com\/index.php?rest_route=\/wp\/v2\/posts\/26910\/revisions"}],"wp:attachment":[{"href":"http:\/\/bangla.sitestree.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=26910"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/bangla.sitestree.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=26910"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/bangla.sitestree.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=26910"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}