JDOM / NOTES</>↗JDOM02 May 2009
The program below will show you how to add attributes to an XML elements. Using JDOM library this can be easily done by calling the Element‘s setAttribute(String name, String value) method. package org.kodejava.jdom; import org.jdom2.Document; import org.jdom2.Element; import org.jdom2.output.Format; import org.jdom2.output.XMLOutputter; public class JDOMAddAttribute { public static void main(String[] args) { Document doc = new […]
JDOM / NOTES</>↗JDOM28 Apr 2009
In this small program you can see how to use JDOM to create a simple xml file. Below you’ll see how to create elements of the xml document, set some text for the element. After that you can see how to use the XMLOutputter class to write the JDOM document into file and display it […]
JDOM / NOTES</>↗JDOM28 Apr 2009
The following example show you how to create a simple Document object in JDOM. We can create a new document directly by creating a new instance of the Document class, for additional information we can pass an Element as an argument. To create a Document from an existing XML file we can use the SAXBuilder. […]
SWING / NOTES</>↗Swing24 Apr 2009
In this example you can see how we can read the items of a JList component. We also obtain the size or the number of items in the JList components. This can be done by calling JList‘s getModel() method which return a ListModel object. From the ListModel we can get the items size, and we […]
SWING / NOTES</>↗Swing22 Apr 2009
The cell width and height of a JList can be defined by setting the fixedCellWidth and fixedCellHeight properties. These properties have a corresponding methods called setFixedCellWidth(int width) and setFixedCellHeight(int height). package org.kodejava.swing; import javax.swing.*; import java.awt.*; import java.util.Vector; public class JListCellWidthAndHeight extends JFrame { public JListCellWidthAndHeight() { initialize(); } public static void main(String[] args) { […]
SWING / NOTES</>↗Swing18 Apr 2009
JList is a component that displays a list of objects and allow user to select one or more items. To create an instance of JList we can pass a vector, an array of objects or a ListModel. In this example we will pass an array of objects that contains a date, string and numbers as […]