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…

JTable with ListSelectionListener and getSelectedRow

The getSelectionRow () returns an integer value of the selected row . Program       Program Source import javax.swing.JFrame; import javax.swing.JTable; import javax.swing.JTextArea; import javax.swing.JScrollPane; import javax.swing.ListSelectionModel; import javax.swing.event.ListSelectionListener; import javax.swing.event.ListSelectionEvent; import java.awt.Dimension; import java.awt.FlowLayout; class Frame extends JFrame implements ListSelectionListener{ private JTable jt; private JTextArea ta; private ListSelectionModel ls; private String[] heading = … Read more…

JTable

JTabel provides a very flexible capability for creating and displaying tables. It allows tables that can be constructed from arrays and vectors of objects. Program       Program Source import javax.swing.JFrame; import javax.swing.JTable; import javax.swing.JScrollPane; import java.awt.Dimension; import java.awt.FlowLayout; class Frame extends JFrame { Frame() { setTitle(“JTable”); setLayout(new FlowLayout()); setJTable(); setSize(700,200); setVisible(true); setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); } … Read more…

JList Multiple Selection with getSelectedIndices

The getSelectionIndecies () returns an array of all of the selected indices, in increasing order. Program       Program Source import javax.swing.JFrame; import javax.swing.JList; import javax.swing.JButton; import javax.swing.JScrollPane; import javax.swing.ImageIcon; import javax.swing.event.ListSelectionListener; import javax.swing.event.ListSelectionEvent; import java.awt.FlowLayout; import java.awt.Dimension; import java.util.Arrays; class Frame extends JFrame implements ListSelectionListener { private JList list; private JButton image; private … Read more…