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…

JList with ListSelectionModel.SINGLE_INTERVAL_SELECTION and ListSelectionModel.SINGLE_SELECTION

A JList allows the user to select multiple ranges of items within the list, but you can change this behavior by calling setSelectionMode( ), which is defined by JList. It is shown here: void setSelectionMode(int mode) Here, mode specifies the selection mode. It must be one of these values defined by¬†ListSelectionModel: SINGLE_SELECTION SINGLE_INTERVAL_SELECTION MULTIPLE_INTERVAL_SELECTION The … Read more…

JList with ListSelectionListener

A JList generates a ListSelectionEvent when the user makes or changes a selection. This event is also generated when the user deselects an item. It is handled by implementing ListSelectionListener. The getSelectedIndexes( ) returns an array containing the indexes of the currently selected items. Program       Program Source import javax.swing.JFrame; import javax.swing.JButton; import … Read more…

JList

The JList class is a single or multiple selection which list with multiple elements. Program       Program Source import javax.swing.JFrame; import javax.swing.JList; import javax.swing.JScrollPane; import java.awt.Dimension; import java.awt.FlowLayout; class Frame extends JFrame { Frame() { setTitle(“JList”); setLayout(new FlowLayout()); setJList(); setSize(700,250); setVisible(true); setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); } private void setJList() { String[] names = {“Nokia”,”Samsung”,”Htc”,”Sony”, “Apple”,”Sony Ericsson”,”Philips”, … Read more…