Browse DevX
Sign up for e-mail newsletters from DevX


Roll Your Own Swing-based XML Editor (Part III)

Learn how to create JMenu components to enhance your Swing applications so that they utilize menus, access the file system, and allow users to cancel actions.




Building the Right Environment to Support AI, Machine Learning and Deep Learning

Editor's note: This is the third and final part of a series about how to build your own XML editor.

f you've been looking for a cross-platform, open-source, XML editor, you've likely come up short. In this three-part series of articles I will walk you through the development of a simple, no frills, XML editor, utilizing several of the most common Java 2 Swing components. This series will be beneficial to anyone wanting to write their own XML editor, or just to those of you looking to learn or brush up on Swing.

This is the third article in the series. In the first article, we briefly discussed XML and why a tree structure is appropriate to display XML, how to handle XML data, how to work with the JTree Swing component, and we built a reusable component that is capable of parsing an XML document and displaying its data in a JTree.

In the second article, we created the framework for our XML editor. In order to do so, we covered a variety of Swing components (including JSplitPane, JScrollPane, JButton, and JTextArea). The JSplitPane object contained two JScrollPane objects, one to house the graphical view of the XML, the other to house the textual view.

In this final article, we will add the finishing touches to our XML editor to make it more user-friendly. We will start by building a menu system, then move on to constructing JFileChooser components to access the underlying file system to allow XML documents to be saved and new documents to be opened. Finally, we will use a JDialog box to allow the user to cancel a command to exit the application.

How can I enhance my Swing applications so that they utilize menus, access the file system, and allow users to cancel actions?

Create JMenu components to handle the application's menus, JFileChooser components to access the underlying file system, and use a JDialog box to allow users to cancel actions.


  • Build the menu components
  • Handle the menu events
  • Build the file system access components
  • Build the dialog component to verify choices
  • Conclusion

    In the previous article, we developed the XTree class, a reusable component derived from the JTree class and capable of displaying XML data as a graphical tree. Because of our keen use of object-oriented principles, none of the changes we will make today will require us to touch that class. It is a self-contained reusable class that is used by, but not coupled with our JFrame container.

  • Thanks for your registration, follow us on our social networks to keep up-to-date