{"id":10221,"date":"2014-06-06T16:26:04","date_gmt":"2014-06-06T13:26:04","guid":{"rendered":"http:\/\/examples.javacodegeeks.com\/?p=10221"},"modified":"2021-08-10T11:50:02","modified_gmt":"2021-08-10T08:50:02","slug":"java-jframe-example","status":"publish","type":"post","link":"https:\/\/examples.javacodegeeks.com\/java-jframe-example\/","title":{"rendered":"Java JFrame Example"},"content":{"rendered":"<p>In this article, we include a Java JFrame tutorial through examples. We will discuss some of the main methods and how JFrame and other main classes like JPanel, JLabel, and JButton fit into the Swing hierarchy. We will then create a simple GUI using the <code>javax.swing<\/code> package. <\/p>\n<h2 class=\"wp-block-heading\" id=\"h-1-introduction\">1. Introduction<\/h2>\n<p><a href=\"https:\/\/docs.oracle.com\/javase\/tutorial\/uiswing\/start\/about.html\">JFC<\/a> (Java foundation classes) encompasses a group of features for building graphical user interfaces (GUI) and adding rich graphics functionality and interactivity to Java applications. It contains: Swing GUI components (includes everything from buttons to split panes to tables), pluggable look and feel support, accessibility API, Java 2D API, and internationalization. <\/p>\n<p>A frame (part of Swing GUI component), implemented as an instance of <code>JFrame<\/code>, is a window that has decorations such as a border, a title, and supports button components that close or iconify the window. <\/p>\n<h2 class=\"wp-block-heading\" id=\"h-2-swing-hierarchy\">2. Swing hierarchy<\/h2>\n<p>The swing API has 18 public packages. Most programs majorly use javax.swing package.  Let us look at the Swing hierarchy concentrating mainly on JFrame, JPanel, JButton and JLabel.<\/p>\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter\"><img decoding=\"async\" width=\"641\" height=\"414\" src=\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2019\/09\/Swing_Hierarchy-wm-1.png\" alt=\"Java JFrame - Swing hierarchy to highlight JFrame, JPanel, JLabel and JButton \" class=\"wp-image-78508\" srcset=\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2019\/09\/Swing_Hierarchy-wm-1.png 641w, https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2019\/09\/Swing_Hierarchy-wm-1-300x194.png 300w\" sizes=\"(max-width: 641px) 100vw, 641px\" \/><figcaption> Fig 1. Swing hierarchy to highlight JFrame, JPanel, JLabel and JButton <\/figcaption><\/figure>\n<\/div>\n<h2 class=\"wp-block-heading\" id=\"h-3-jframe\">3. JFrame<\/h2>\n<p><a href=\"https:\/\/docs.oracle.com\/javase\/8\/docs\/api\/javax\/swing\/JFrame.html\">JFrame<\/a> is an extended version of java.awt.Frame that adds support for JFC\/ Swing component architecture. Like all other JFC\/ Swing top-level containers, a JFrame contains a JRootPane as its only child.  The&nbsp;content pane&nbsp;provided by the root pane should, as a rule, contain all the non-menu components displayed by the JFrame. Let us look at the methods available in JFrame<\/p>\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter\"><img decoding=\"async\" width=\"500\" height=\"485\" src=\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2019\/09\/JFrame-wm.png\" alt=\"Java JFrame - JFrame UML class diagram\" class=\"wp-image-78547\" srcset=\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2019\/09\/JFrame-wm.png 500w, https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2019\/09\/JFrame-wm-300x291.png 300w\" sizes=\"(max-width: 500px) 100vw, 500px\" \/><figcaption>Fig 2. JFrame UML class diagram<\/figcaption><\/figure>\n<\/div>\n<p>Let us now look at these methods and descriptions. Refer <a href=\"https:\/\/docs.oracle.com\/javase\/8\/docs\/api\/javax\/swing\/JFrame.html\">Java docs<\/a> for more details. We will use some of these methods in our example.<\/p>\n<ul class=\"wp-block-list\">\n<li><code>protected void addImpl(Component comp, Object constraints, int index)<\/code> : Adds the specified child Component. This method is overridden to conditionally forward calls to the contentPane. By default, children are added to the contentPane instead of the frame<\/li>\n<li><code>protected JRootPane createRootPane() <\/code>: Called by the constructor methods to create the default rootPane.<\/li>\n<li><code>protected void frameInit() <\/code>: Called by the constructors to init the JFrame properly.<\/li>\n<li><code>public AccessibleContext getAccessibleContext()<\/code> : Gets the AccessibleContext associated with this JFrame. For JFrames, the AccessibleContext takes the form of an AccessibleJFrame. A new AccessibleJFrame instance is created if necessary.<\/li>\n<li><code>public Container getContentPane() <\/code>: Returns the contentPane object for this frame.<\/li>\n<li><code>public int getDefaultCloseOperation()<\/code> : Returns the operation that occurs when the user initiates a &#8220;close&#8221; on this frame.<\/li>\n<li><code>public Component getGlassPane()<\/code> : Returns the glassPane object for this frame.<\/li>\n<li><code>public Graphics getGraphics()<\/code> : Creates a graphics context for this component. This method will return null if this component is currently not displayable.<\/li>\n<li><code>public JMenuBar getJMenuBar()<\/code> : Returns the menubar set on this frame.<\/li>\n<li><code>public JLayeredPane getLayeredPane()<\/code> : Returns the layeredPane object for this frame.<\/li>\n<li><code>public JRootPane getRootPane()<\/code> : Returns the rootPane object for this frame.<\/li>\n<li><code>public TransferHandler getTransferHandler() <\/code>: Gets the transferHandler property.<\/li>\n<li><code>public static boolean isDefaultLookAndFeelDecorated()<\/code><em> <\/em>: Returns true if newly created JFrames should have their Window decorations provided by the current look and feel.<\/li>\n<li><code>protected boolean isRootPaneCheckingEnabled()<\/code> : Returns whether calls to add and setLayout are forwarded to the contentPane.<\/li>\n<li><code>protected String paramString()<\/code> : Returns a string representation of this JFrame. This method is intended to be used only for debugging purposes, and the content and format of the returned string may vary between implementations.<\/li>\n<li><code>protected void processWindowEvent(WindowEvent e)<\/code> : Processes window events occurring on this component. Hides the window or disposes of it, as specified by the setting of the defaultCloseOperation property.<\/li>\n<li><code>public void remove(Component comp)<\/code> :  Removes the specified component from the container. If comp is not the rootPane, this will forward the call to the contentPane. This will do nothing if comp is not a child of the JFrame or contentPane.<\/li>\n<li><code>public void repaint(long time, int x, int y, int width, int height)<\/code> : Repaints the specified rectangle of this component within time milliseconds.<\/li>\n<li><code>public void setContentPane(Container contentPane)<\/code> : Sets the contentPane property. This method is called by the constructor.<\/li>\n<li><code>public void setDefaultCloseOperation(int operation)<\/code> : Sets the operation that will happen by default when the user initiates a &#8220;close&#8221; on this frame. Choices available are &#8211; <code>DO_NOTHING_ON_CLOSE<\/code>, <code>HIDE_ON_CLOSE<\/code>, <code>DISPOSE_ON_CLOSE<\/code> and <code>EXIT_ON_CLOSE<\/code>. The value is set to <code>HIDE_ON_CLOSE<\/code> by default.<\/li>\n<li><code>public static void setDefaultLookAndFeelDecorated(boolean defaultLookAndFeelDecorated)<\/code> : Provides a hint as to whether or not newly created JFrames should have their Window decorations (such as borders, widgets to close the window) provided by the current look and feel. <\/li>\n<li><code>public void setGlassPane(Component glassPane)<\/code> : Sets the glassPane property. This method is called by the constructor.<\/li>\n<li><code>public void setIconImage(Image image)<\/code> : Sets the image to be displayed as the icon for this window.<\/li>\n<li><code>public void setJMenuBar(JMenuBar menubar)<\/code> : Sets the menubar for this frame.<\/li>\n<li><code>public void setLayeredPane(JLayeredPane layeredPane)<\/code> : Sets the layeredPane property. This method is called by the constructor.<\/li>\n<li><code>public void setLayout(LayoutManager manager)<\/code> : Sets the LayoutManager.<\/li>\n<li><code>protected void setRootPane(JRootPane root)<\/code> : Sets the rootPane property. This method is called by the constructor.<\/li>\n<li><code>protected void setRootPaneCheckingEnabled(boolean enabled)<\/code> : Sets whether calls to add and setLayout are forwarded to the contentPane.<\/li>\n<li><code>public void setTransferHandler(TransferHandler newHandler)<\/code> : Sets the transferHandler property, which is a mechanism to support the transfer of data into this component. Use null if the component does not support data transfer operations.<\/li>\n<li><code>public void update(Graphics g) <\/code>: Just calls paint(g).<\/li>\n<\/ul>\n<h2 class=\"wp-block-heading\" id=\"h-4-jpanel\">4. JPanel<\/h2>\n<p>JPanel is a generic lightweight container. Let us look at some of the commonly used methods of JPanel. These are inherited from <code>javax.swing.JComponent<\/code> and <code>java.awt.Container<\/code><div style=\"display:inline-block; margin: 15px 0;\"> <div id=\"adngin-JavaCodeGeeks_incontent_video-0\" style=\"display:inline-block;\"><\/div> <\/div><\/p>\n<ul class=\"wp-block-list\">\n<li><code>public void setLayout(LayoutManager mgr)<\/code> : Sets the layout manager for this container. This method changes layout-related information<\/li>\n<li><code>public void setBorder(Border border)<\/code> : Sets the border of this component. The Border object is responsible for defining the insets for the component<\/li>\n<\/ul>\n<h2 class=\"wp-block-heading\" id=\"h-5-jbutton\">5. JButton<\/h2>\n<p>JButton is an implementation of a &#8220;push&#8221; button. Buttons can be configured, and to some degree controlled by Actions. Some commonly used methods of JButton are: <\/p>\n<ul class=\"wp-block-list\">\n<li><code>public void setText(String text)<\/code> : Sets the button&#8217;s text.<\/li>\n<li><code>public void setIcon(Icon defaultIcon)<\/code> : Sets the button&#8217;s default icon<\/li>\n<li><code>public void addActionListener(ActionListener l)<\/code> : Adds an ActionListener to the button.<\/li>\n<\/ul>\n<h2 class=\"wp-block-heading\" id=\"h-6-jlabel\">6. JLabel<\/h2>\n<p>A JLabel is a display area for a short text string or an image or both. A label does not react to input events. As a result, it cannot get the keyboard focus. Some commonly used methods are:<\/p>\n<ul class=\"wp-block-list\">\n<li><code>public void setIcon(Icon icon)<\/code> : Defines the icon this component will display. If the value of icon is null, nothing is displayed. The default value of this property is null.<\/li>\n<li><code>public void setText(String text) <\/code>: Defines the single line of text this component will display. If the value of text is null or empty string, nothing is displayed. The default value of this property is null.<\/li>\n<\/ul>\n<h2 class=\"wp-block-heading\" id=\"h-7-java-jframe-example\">7. Java JFrame Example<\/h2>\n<p>Let us now look at an example using the above discussed components.<\/p>\n<p><span style=\"text-decoration: underline\"><em>JFrameExample.java<\/em><\/span><\/p>\n<pre class=\"brush:java\">import javax.swing.*;\nimport java.awt.FlowLayout;\nimport java.awt.GridBagConstraints;\nimport java.awt.GridBagLayout;\nimport java.awt.Insets;\nimport java.awt.event.*;\n\npublic class JFrameExample{\n\t\n\tpublic static void main(String[] args){\n\t\t\/\/ Create frame with title Registration Demo\n\t\tJFrame frame= new JFrame();\t\n\t\tframe.setTitle(\"JFrame Registration Demo\");\n\t\t\n               \/\/ Panel to define the layout. We are using GridBagLayout\n\t\tJPanel mainPanel = new JPanel();\n\t\tmainPanel.setLayout(new BoxLayout(mainPanel, BoxLayout.Y_AXIS));\n\n\t\tJPanel headingPanel = new JPanel();\n\t\tJLabel headingLabel = new JLabel(\"This is the heading panel for our demo course\");\n\t\theadingPanel.add(headingLabel);\n\t\t\n               \/\/ Panel to define the layout. We are using GridBagLayout\n\t\tJPanel panel = new JPanel(new GridBagLayout());\n\t\t\/\/ Constraints for the layout\n\t\tGridBagConstraints constr = new GridBagConstraints();\n\t\tconstr.insets = new Insets(5, 5, 5, 5);\t\t\n\t\tconstr.anchor = GridBagConstraints.WEST;\n\n\t\t\/\/ Set the initial grid values to 0,0\n\t\tconstr.gridx=0;\n\t\tconstr.gridy=0;\n \n\t\t\/\/ Declare the required Labels\n\t\tJLabel userNameLabel = new JLabel(\"Enter your name :\");\n\t\tJLabel pwdLabel = new JLabel(\"Enter your password :\");\n\t\tJLabel emailLabel = new JLabel(\"Enter email :\");\n        \n\t\t\/\/ Declare Text fields\n\t\tJTextField userNameTxt = new JTextField(20);\n\t\tJPasswordField pwdTxt = new JPasswordField(20);\n\t\tJTextField emailTxt = new JTextField(20);\n\t\t\n\t\tpanel.add(userNameLabel, constr);\n\t\tconstr.gridx=1;\n\t\tpanel.add(userNameTxt, constr);\n\t\tconstr.gridx=0; constr.gridy=1;\n\t\t\n\t\tpanel.add(pwdLabel, constr);\n\t\tconstr.gridx=1;\n\t\tpanel.add(pwdTxt, constr);\n\t\tconstr.gridx=0; constr.gridy=2;\n\t\t\n\t\tpanel.add(emailLabel, constr);\n\t\tconstr.gridx=1;\n\t\tpanel.add(emailTxt, constr);\n\t\tconstr.gridy=3;\n\t\t\n\t\tconstr.gridwidth = 2;\n\t\tconstr.anchor = GridBagConstraints.CENTER;\n \n                \/\/ Button with text \"Register\"\n\t\tJButton button = new JButton(\"Register\");\n\t\t\/\/ add a listener to button\n\t\tbutton.addActionListener(new ActionListener()\n\t\t{\n\t\t  public void actionPerformed(ActionEvent e)\n\t\t  {\n\t\t\theadingLabel.setText(\"Thanks for registering. We'll get back to you shortly.\");\n\t\t\tuserNameTxt.setText(\"\");\n\t\t\tpwdTxt.setText(\"\");\n\t\t\temailTxt.setText(\"\");\n\t\t  }\n\t\t});\n \n               \/\/ Add label and button to panel\n               panel.add(button, constr);\n \n\t\tmainPanel.add(headingPanel);\n\t\tmainPanel.add(panel);\n\n\t\t\/\/ Add panel to frame\n\t\tframe.add(mainPanel);\n\t\tframe.pack();\n                frame.setSize(400, 400);\n                frame.setLocationRelativeTo(null);\n                frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);\n\t\tframe.setVisible(true);\n\t}\n}\n<\/pre>\n<p>Let&#8217;s explain the above code. First, we create frame and panel containers by using <a href=\"http:\/\/docs.oracle.com\/javase\/7\/docs\/api\/javax\/swing\/JFrame.html\"><code>JFrame<\/code><\/a> and <a href=\"http:\/\/docs.oracle.com\/javase\/7\/docs\/api\/javax\/swing\/JPanel.html\"><code>JPanel<\/code><\/a>. We created two panels in this example. The <code>headingPanel<\/code> contains a label to indicate some details. The second panel holds the required fields, labels and buttons. We used the <a href=\"https:\/\/docs.oracle.com\/javase\/tutorial\/uiswing\/layout\/box.html\">BoxLayout<\/a> for the main panel in this example. Next, we add components like labels and button to the panel to the second panel using the <a href=\"https:\/\/docs.oracle.com\/javase\/tutorial\/uiswing\/layout\/gridbag.html\">GridBagLayout<\/a>.<\/p>\n<p>Text fields and labels for user name, password, email and button are added to the main panel using JLabel, JTextField, JButton, and JPasswordField. An action listener is defined for the button to reset the fields when the button is clicked. We then declare the size of the window frame and then the location using  <code>setLocation(x, y)<\/code> or the <code>setLocationRelativeTo(component)<\/code> method. In this case, we use the <code>setLocationRelativeTo(null)<\/code> that places the frame to the center of the screen. We then define the action of the frame when we press the close button. The close button of the frame by default performs the hide operation for the <code>JFrame<\/code>. In this example, we changed this behavior to window close operation by setting the <code>setDefaultCloseOperation()<\/code> to<code> EXIT_ON_CLOSE<\/code> value. Finally, we make the frame visible by using the <code>setVisible(true)<\/code> method.<\/p>\n<p>The result would be displayed as below:<\/p>\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter\"><img decoding=\"async\" width=\"389\" height=\"394\" src=\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2019\/09\/JFrameExample-wm-1.png\" alt=\"Java JFrame - first screen to enter data\" class=\"wp-image-78650\" srcset=\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2019\/09\/JFrameExample-wm-1.png 389w, https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2019\/09\/JFrameExample-wm-1-296x300.png 296w, https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2019\/09\/JFrameExample-wm-1-70x70.png 70w\" sizes=\"(max-width: 389px) 100vw, 389px\" \/><figcaption>Java JFrameFig 3. JFrame example &#8211; first screen to enter data<\/figcaption><\/figure>\n<\/div>\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter\"><img decoding=\"async\" width=\"389\" height=\"396\" src=\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2019\/09\/JFrameExample1-wm.png\" alt=\"Java JFrame - after data input\" class=\"wp-image-78651\" srcset=\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2019\/09\/JFrameExample1-wm.png 389w, https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2019\/09\/JFrameExample1-wm-295x300.png 295w, https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2019\/09\/JFrameExample1-wm-70x70.png 70w\" sizes=\"(max-width: 389px) 100vw, 389px\" \/><figcaption>Fig 4. JFrame example &#8211; after data input<\/figcaption><\/figure>\n<\/div>\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter\"><img decoding=\"async\" width=\"389\" height=\"396\" src=\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2019\/09\/JFrameExample2-wm.png\" alt=\"Java JFrame - after Register button is clicked. Note the change in label\" class=\"wp-image-78653\" srcset=\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2019\/09\/JFrameExample2-wm.png 389w, https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2019\/09\/JFrameExample2-wm-295x300.png 295w, https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2019\/09\/JFrameExample2-wm-70x70.png 70w\" sizes=\"(max-width: 389px) 100vw, 389px\" \/><figcaption>Fig 5. JFrame example &#8211; after the Register button is clicked. Note the change in label<\/figcaption><\/figure>\n<\/div>\n<h2 class=\"wp-block-heading\" id=\"h-8-more-articles\">8. More articles<\/h2>\n<ul class=\"wp-block-list\">\n<li><a href=\"https:\/\/examples.javacodegeeks.com\/java-tutorial-for-beginners\/\">Java Tutorial for Beginners (with video)<\/a><\/li>\n<li><a href=\"https:\/\/examples.javacodegeeks.com\/java-array-example\/\">Java Array \u2013 java.util.Arrays Example (with Video)<\/a><\/li>\n<li><a href=\"https:\/\/examples.javacodegeeks.com\/java-string-class-example\/\">Java String Class Example (with video)<\/a><\/li>\n<li><a href=\"https:\/\/examples.javacodegeeks.com\/java-util-scanner-scanner-java-example\/\">java.util.Scanner \u2013 Scanner Java Example (with video)<\/a><\/li>\n<li><a href=\"https:\/\/examples.javacodegeeks.com\/java-random-number-generator-example\/\">Java random number generator Example<\/a><\/li>\n<li><a href=\"https:\/\/examples.javacodegeeks.com\/java-set-example\/\">Java Set Example (with video)<\/a><\/li>\n<\/ul>\n<h2 class=\"wp-block-heading\" id=\"h-9-download-the-source-code\">9. Download the Source Code<\/h2>\n<p>That was a JFrame Java Example.<\/p>\n<p>This was an example of how to use the class <a href=\"http:\/\/docs.oracle.com\/javase\/7\/docs\/api\/javax\/swing\/JFrame.html\"><code>JFrame<\/code><\/a>. <\/p>\n<div class=\"download\"><strong>Download<\/strong><br \/>\nYou can download the source of this tutorial here: <a href=\"http:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2019\/09\/JFrameExample.zip\"><strong>Java JFrame Example<\/strong><\/a><\/div>\n<p><strong>Last updated on Aug. 10th, 2021<\/strong><\/p>\n","protected":false},"excerpt":{"rendered":"<p>In this article, we include a Java JFrame tutorial through examples. We will discuss some of the main methods and how JFrame and other main classes like JPanel, JLabel, and JButton fit into the Swing hierarchy. We will then create a simple GUI using the javax.swing package. 1. Introduction JFC (Java foundation classes) encompasses a &hellip;<\/p>\n","protected":false},"author":192,"featured_media":1204,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[143],"tags":[213,219,591],"class_list":["post-10221","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-jframe","tag-jbutton-2","tag-jlabel-2","tag-jpanel"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v26.5 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>Java JFrame Example - Java Code Geeks<\/title>\n<meta name=\"description\" content=\"In this article, we include a Java JFrame tutorial through examples. We will discuss some of the main methods and how JFrame and other main classes like\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/examples.javacodegeeks.com\/java-jframe-example\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Java JFrame Example - Java Code Geeks\" \/>\n<meta property=\"og:description\" content=\"In this article, we include a Java JFrame tutorial through examples. We will discuss some of the main methods and how JFrame and other main classes like\" \/>\n<meta property=\"og:url\" content=\"https:\/\/examples.javacodegeeks.com\/java-jframe-example\/\" \/>\n<meta property=\"og:site_name\" content=\"Examples Java Code Geeks\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/javacodegeeks\" \/>\n<meta property=\"article:published_time\" content=\"2014-06-06T13:26:04+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2021-08-10T08:50:02+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2012\/12\/java-logo.jpg\" \/>\n\t<meta property=\"og:image:width\" content=\"150\" \/>\n\t<meta property=\"og:image:height\" content=\"150\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/jpeg\" \/>\n<meta name=\"author\" content=\"Venkat-Raman Nagarajan\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@javacodegeeks\" \/>\n<meta name=\"twitter:site\" content=\"@javacodegeeks\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Venkat-Raman Nagarajan\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"9 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\/\/examples.javacodegeeks.com\/java-jframe-example\/#article\",\"isPartOf\":{\"@id\":\"https:\/\/examples.javacodegeeks.com\/java-jframe-example\/\"},\"author\":{\"name\":\"Venkat-Raman Nagarajan\",\"@id\":\"https:\/\/examples.javacodegeeks.com\/#\/schema\/person\/63fc282a07315e6519d0b124f8690c4c\"},\"headline\":\"Java JFrame Example\",\"datePublished\":\"2014-06-06T13:26:04+00:00\",\"dateModified\":\"2021-08-10T08:50:02+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/examples.javacodegeeks.com\/java-jframe-example\/\"},\"wordCount\":1238,\"commentCount\":3,\"publisher\":{\"@id\":\"https:\/\/examples.javacodegeeks.com\/#organization\"},\"image\":{\"@id\":\"https:\/\/examples.javacodegeeks.com\/java-jframe-example\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2012\/12\/java-logo.jpg\",\"keywords\":[\"jbutton\",\"jlabel\",\"JPanel\"],\"articleSection\":[\"JFrame\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\/\/examples.javacodegeeks.com\/java-jframe-example\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/examples.javacodegeeks.com\/java-jframe-example\/\",\"url\":\"https:\/\/examples.javacodegeeks.com\/java-jframe-example\/\",\"name\":\"Java JFrame Example - Java Code Geeks\",\"isPartOf\":{\"@id\":\"https:\/\/examples.javacodegeeks.com\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\/\/examples.javacodegeeks.com\/java-jframe-example\/#primaryimage\"},\"image\":{\"@id\":\"https:\/\/examples.javacodegeeks.com\/java-jframe-example\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2012\/12\/java-logo.jpg\",\"datePublished\":\"2014-06-06T13:26:04+00:00\",\"dateModified\":\"2021-08-10T08:50:02+00:00\",\"description\":\"In this article, we include a Java JFrame tutorial through examples. We will discuss some of the main methods and how JFrame and other main classes like\",\"breadcrumb\":{\"@id\":\"https:\/\/examples.javacodegeeks.com\/java-jframe-example\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/examples.javacodegeeks.com\/java-jframe-example\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/examples.javacodegeeks.com\/java-jframe-example\/#primaryimage\",\"url\":\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2012\/12\/java-logo.jpg\",\"contentUrl\":\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2012\/12\/java-logo.jpg\",\"width\":150,\"height\":150,\"caption\":\"Bipartite Graph\"},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/examples.javacodegeeks.com\/java-jframe-example\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/examples.javacodegeeks.com\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Java Development\",\"item\":\"https:\/\/examples.javacodegeeks.com\/category\/java-development\/\"},{\"@type\":\"ListItem\",\"position\":3,\"name\":\"Desktop Java\",\"item\":\"https:\/\/examples.javacodegeeks.com\/category\/java-development\/desktop-java\/\"},{\"@type\":\"ListItem\",\"position\":4,\"name\":\"swing\",\"item\":\"https:\/\/examples.javacodegeeks.com\/category\/java-development\/desktop-java\/swing\/\"},{\"@type\":\"ListItem\",\"position\":5,\"name\":\"JFrame\",\"item\":\"https:\/\/examples.javacodegeeks.com\/category\/java-development\/desktop-java\/swing\/jframe\/\"},{\"@type\":\"ListItem\",\"position\":6,\"name\":\"Java JFrame Example\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/examples.javacodegeeks.com\/#website\",\"url\":\"https:\/\/examples.javacodegeeks.com\/\",\"name\":\"Java Code Geeks\",\"description\":\"Java Examples and Code Snippets\",\"publisher\":{\"@id\":\"https:\/\/examples.javacodegeeks.com\/#organization\"},\"alternateName\":\"JCG\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/examples.javacodegeeks.com\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Organization\",\"@id\":\"https:\/\/examples.javacodegeeks.com\/#organization\",\"name\":\"Exelixis Media P.C.\",\"url\":\"https:\/\/examples.javacodegeeks.com\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/examples.javacodegeeks.com\/#\/schema\/logo\/image\/\",\"url\":\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2022\/06\/exelixis-logo.png\",\"contentUrl\":\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2022\/06\/exelixis-logo.png\",\"width\":864,\"height\":246,\"caption\":\"Exelixis Media P.C.\"},\"image\":{\"@id\":\"https:\/\/examples.javacodegeeks.com\/#\/schema\/logo\/image\/\"},\"sameAs\":[\"https:\/\/www.facebook.com\/javacodegeeks\",\"https:\/\/x.com\/javacodegeeks\"]},{\"@type\":\"Person\",\"@id\":\"https:\/\/examples.javacodegeeks.com\/#\/schema\/person\/63fc282a07315e6519d0b124f8690c4c\",\"name\":\"Venkat-Raman Nagarajan\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/examples.javacodegeeks.com\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2019\/08\/venkat.nagarajan-96x96.jpg\",\"contentUrl\":\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2019\/08\/venkat.nagarajan-96x96.jpg\",\"caption\":\"Venkat-Raman Nagarajan\"},\"description\":\"Venkat works for a major IT firm in India and has more than a decade of experience working and managing Java projects for a banking client.\",\"url\":\"https:\/\/examples.javacodegeeks.com\/author\/venkat-raman-nagarajan\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Java JFrame Example - Java Code Geeks","description":"In this article, we include a Java JFrame tutorial through examples. We will discuss some of the main methods and how JFrame and other main classes like","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/examples.javacodegeeks.com\/java-jframe-example\/","og_locale":"en_US","og_type":"article","og_title":"Java JFrame Example - Java Code Geeks","og_description":"In this article, we include a Java JFrame tutorial through examples. We will discuss some of the main methods and how JFrame and other main classes like","og_url":"https:\/\/examples.javacodegeeks.com\/java-jframe-example\/","og_site_name":"Examples Java Code Geeks","article_publisher":"https:\/\/www.facebook.com\/javacodegeeks","article_published_time":"2014-06-06T13:26:04+00:00","article_modified_time":"2021-08-10T08:50:02+00:00","og_image":[{"width":150,"height":150,"url":"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2012\/12\/java-logo.jpg","type":"image\/jpeg"}],"author":"Venkat-Raman Nagarajan","twitter_card":"summary_large_image","twitter_creator":"@javacodegeeks","twitter_site":"@javacodegeeks","twitter_misc":{"Written by":"Venkat-Raman Nagarajan","Est. reading time":"9 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/examples.javacodegeeks.com\/java-jframe-example\/#article","isPartOf":{"@id":"https:\/\/examples.javacodegeeks.com\/java-jframe-example\/"},"author":{"name":"Venkat-Raman Nagarajan","@id":"https:\/\/examples.javacodegeeks.com\/#\/schema\/person\/63fc282a07315e6519d0b124f8690c4c"},"headline":"Java JFrame Example","datePublished":"2014-06-06T13:26:04+00:00","dateModified":"2021-08-10T08:50:02+00:00","mainEntityOfPage":{"@id":"https:\/\/examples.javacodegeeks.com\/java-jframe-example\/"},"wordCount":1238,"commentCount":3,"publisher":{"@id":"https:\/\/examples.javacodegeeks.com\/#organization"},"image":{"@id":"https:\/\/examples.javacodegeeks.com\/java-jframe-example\/#primaryimage"},"thumbnailUrl":"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2012\/12\/java-logo.jpg","keywords":["jbutton","jlabel","JPanel"],"articleSection":["JFrame"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/examples.javacodegeeks.com\/java-jframe-example\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/examples.javacodegeeks.com\/java-jframe-example\/","url":"https:\/\/examples.javacodegeeks.com\/java-jframe-example\/","name":"Java JFrame Example - Java Code Geeks","isPartOf":{"@id":"https:\/\/examples.javacodegeeks.com\/#website"},"primaryImageOfPage":{"@id":"https:\/\/examples.javacodegeeks.com\/java-jframe-example\/#primaryimage"},"image":{"@id":"https:\/\/examples.javacodegeeks.com\/java-jframe-example\/#primaryimage"},"thumbnailUrl":"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2012\/12\/java-logo.jpg","datePublished":"2014-06-06T13:26:04+00:00","dateModified":"2021-08-10T08:50:02+00:00","description":"In this article, we include a Java JFrame tutorial through examples. We will discuss some of the main methods and how JFrame and other main classes like","breadcrumb":{"@id":"https:\/\/examples.javacodegeeks.com\/java-jframe-example\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/examples.javacodegeeks.com\/java-jframe-example\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/examples.javacodegeeks.com\/java-jframe-example\/#primaryimage","url":"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2012\/12\/java-logo.jpg","contentUrl":"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2012\/12\/java-logo.jpg","width":150,"height":150,"caption":"Bipartite Graph"},{"@type":"BreadcrumbList","@id":"https:\/\/examples.javacodegeeks.com\/java-jframe-example\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/examples.javacodegeeks.com\/"},{"@type":"ListItem","position":2,"name":"Java Development","item":"https:\/\/examples.javacodegeeks.com\/category\/java-development\/"},{"@type":"ListItem","position":3,"name":"Desktop Java","item":"https:\/\/examples.javacodegeeks.com\/category\/java-development\/desktop-java\/"},{"@type":"ListItem","position":4,"name":"swing","item":"https:\/\/examples.javacodegeeks.com\/category\/java-development\/desktop-java\/swing\/"},{"@type":"ListItem","position":5,"name":"JFrame","item":"https:\/\/examples.javacodegeeks.com\/category\/java-development\/desktop-java\/swing\/jframe\/"},{"@type":"ListItem","position":6,"name":"Java JFrame Example"}]},{"@type":"WebSite","@id":"https:\/\/examples.javacodegeeks.com\/#website","url":"https:\/\/examples.javacodegeeks.com\/","name":"Java Code Geeks","description":"Java Examples and Code Snippets","publisher":{"@id":"https:\/\/examples.javacodegeeks.com\/#organization"},"alternateName":"JCG","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/examples.javacodegeeks.com\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/examples.javacodegeeks.com\/#organization","name":"Exelixis Media P.C.","url":"https:\/\/examples.javacodegeeks.com\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/examples.javacodegeeks.com\/#\/schema\/logo\/image\/","url":"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2022\/06\/exelixis-logo.png","contentUrl":"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2022\/06\/exelixis-logo.png","width":864,"height":246,"caption":"Exelixis Media P.C."},"image":{"@id":"https:\/\/examples.javacodegeeks.com\/#\/schema\/logo\/image\/"},"sameAs":["https:\/\/www.facebook.com\/javacodegeeks","https:\/\/x.com\/javacodegeeks"]},{"@type":"Person","@id":"https:\/\/examples.javacodegeeks.com\/#\/schema\/person\/63fc282a07315e6519d0b124f8690c4c","name":"Venkat-Raman Nagarajan","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/examples.javacodegeeks.com\/#\/schema\/person\/image\/","url":"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2019\/08\/venkat.nagarajan-96x96.jpg","contentUrl":"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2019\/08\/venkat.nagarajan-96x96.jpg","caption":"Venkat-Raman Nagarajan"},"description":"Venkat works for a major IT firm in India and has more than a decade of experience working and managing Java projects for a banking client.","url":"https:\/\/examples.javacodegeeks.com\/author\/venkat-raman-nagarajan\/"}]}},"_links":{"self":[{"href":"https:\/\/examples.javacodegeeks.com\/wp-json\/wp\/v2\/posts\/10221","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/examples.javacodegeeks.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/examples.javacodegeeks.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/examples.javacodegeeks.com\/wp-json\/wp\/v2\/users\/192"}],"replies":[{"embeddable":true,"href":"https:\/\/examples.javacodegeeks.com\/wp-json\/wp\/v2\/comments?post=10221"}],"version-history":[{"count":0,"href":"https:\/\/examples.javacodegeeks.com\/wp-json\/wp\/v2\/posts\/10221\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/examples.javacodegeeks.com\/wp-json\/wp\/v2\/media\/1204"}],"wp:attachment":[{"href":"https:\/\/examples.javacodegeeks.com\/wp-json\/wp\/v2\/media?parent=10221"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/examples.javacodegeeks.com\/wp-json\/wp\/v2\/categories?post=10221"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/examples.javacodegeeks.com\/wp-json\/wp\/v2\/tags?post=10221"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}