JSpinner with ChangeListener

A jspinner generates an event of type ChangeEvent when an item is selected that is sent to listeners of type ChangeListener. Both types are defined in the javax.swing.event package. To obtain the current value of the jspinner, call getValue( ). It returns the current setting. Program       Progarm Source import javax.swing.JFrame; import javax.swing.JSpinner; … Read more…

JSpinner with SpinnerListModel

SpinnerListModel is a model for a sequence defined by an array of objects of any type. You could use this to use a sequence of strings as the choices in the spinner. Program       Program Source import javax.swing.JFrame; import javax.swing.JSpinner; import javax.swing.SpinnerListModel; import java.awt.FlowLayout; import java.awt.Dimension; class JSpinnerTest extends JFrame { JSpinnerTest() { … Read more…

JSpinner with default value

The JSpinners are like to jcombo boxes and jlists in that they user can select input from a predetermined set of values. Program       Program Source import javax.swing.JFrame; import javax.swing.JSpinner; import java.awt.FlowLayout; import java.awt.Dimension; class JSpinnerTest extends JFrame { JSpinnerTest() { setTitle(“JSpinnerTest”); setLayout(new FlowLayout()); setJSpinner(); setSize(700,200); setVisible(true); setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); } void setJSpinner() { JSpinner js = new JSpinner(); … Read more…

JEditorPane

JEditorPane A text pane that can be used to edit various types of content, including HTML and RTF. getClass()  This method returns an object of type Class that identifies the class of the current object. getResource ()  The getresource() method finds a resource with a given name. This method return the URL object. getResource(String name) Here, … Read more…

JTree with TreeSelectionListener and TreeSelectionEvent

A TreeSelectionEvent is generated when the user selects or deselects a node within the tree. The listeners for these events are TreeSelectionListener. The tree event classes and listener interfaces are packaged in javax.swing.event. You can obtain the path to the selected object by calling getPath( ), shown here, on the event object. TreePath getPath( ) It … Read more…

JTree

A JTree is a component that presents a hierarchical view of data. The user has the ability to expand or collapse individual subtrees in this display. Trees are implemented in Swing by the JTree class. The MutableTreeNode interface extends TreeNode. It declares methods that can insert and remove child nodes or change the parent node.The DefaultMutableTreeNode class implements … Read more…