title: Build GUI in swing using XML file
body: <p>I'm looking for a way to build UI using XML and swing. I have a code in XML and looking for a way to get UI out of it using swing. I tried below Java code but im not sure if this will help me display frame and other components.</p>
  
  <p>Please help.</p>
  
  <p>Below is the XML code which has JFrame and other things I want in my UI. I want to call this file from a java code so that I can display what all I wrote in XML.</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt; 
  &lt;java version="1.8.0_161" class="java.beans.XMLDecoder"&gt; 
   &lt;object class="javax.swing.JFrame"&gt; 
    &lt;void property="size"&gt; 
     &lt;object class="java.awt.Dimension"&gt; 
      &lt;int&gt;208&lt;/int&gt; 
      &lt;int&gt;87&lt;/int&gt; 
     &lt;/object&gt; 
    &lt;/void&gt; 
    &lt;void property="contentPane"&gt; 
     &lt;void method="add"&gt; 
      &lt;object id="JLabel0" class="javax.swing.JLabel"&gt; 
       &lt;void property="text"&gt; 
        &lt;string&gt;Hello1&lt;/string&gt; 
       &lt;/void&gt; 
      &lt;/object&gt; 
     &lt;/void&gt; 
     &lt;void method="add"&gt; 
      &lt;object id="JButton0" class="javax.swing.JButton"&gt; 
       &lt;string&gt;Hello2&lt;/string&gt; 
      &lt;/object&gt; 
     &lt;/void&gt; 
     &lt;void property="layout"&gt; 
      &lt;object class="java.awt.BorderLayout"&gt; 
       &lt;void method="addLayoutComponent"&gt; 
        &lt;object idref="JButton0"/&gt; 
        &lt;string&gt;South&lt;/string&gt; 
       &lt;/void&gt; 
       &lt;void method="addLayoutComponent"&gt; 
        &lt;object idref="JLabel0"/&gt; 
        &lt;string&gt;Center&lt;/string&gt; 
       &lt;/void&gt; 
      &lt;/object&gt; 
     &lt;/void&gt; 
    &lt;/void&gt; 
    &lt;void property="name"&gt; 
     &lt;string&gt;frame0&lt;/string&gt; 
    &lt;/void&gt; 
    &lt;void property="title"&gt; 
     &lt;string&gt;Save/Load View&lt;/string&gt; 
    &lt;/void&gt; 
    &lt;void property="visible"&gt; 
     &lt;boolean&gt;true&lt;/boolean&gt; 
    &lt;/void&gt; 
   &lt;/object&gt; 
  &lt;/java&gt;
  </code></pre>
  
  <p>Below is the Java code:</p>
  
  <pre><code> import javax.swing.*;
   import java.io.File;
   import org.w3c.dom.Document;
   import org.w3c.dom.*; 
   import java.awt.*;
   import java.awt.event.*;
  
  
   import javax.xml.parsers.DocumentBuilderFactory;
   import javax.xml.parsers.DocumentBuilder;
   import org.xml.sax.SAXException;
   import org.xml.sax.SAXParseException; 
  
  public class MasterScreen{
  
  public static void main (String argv []){
   try {
   DocumentBuilderFactory docBuilderFactory = DocumentBuilderFactory.newInstance();
   DocumentBuilder docBuilder = docBuilderFactory.newDocumentBuilder();
   Document doc = docBuilder.parse (new File("MasterXML.xml"));
   System.out.println("Siri");
   doc.getDocumentElement ().normalize ();
   System.out.println("Siriri");
   }
   catch (SAXParseException err) {
       System.out.println ("** Parsing error" + ", line " + err.getLineNumber () + ", uri " + err.getSystemId ());
       System.out.println(" " + err.getMessage ());
  
       }catch (SAXException e) {
       Exception x = e.getException ();
       ((x == null) ? e : x).printStackTrace ();
  
       }catch (Throwable t) {
       t.printStackTrace ();
       }
  }
  }
  </code></pre>