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…

JPanel with JScrollPane

JScrollPane JScrollPane is a lightweight container that automatically handles the scrolling of another component. The component being scrolled can either be an individual component, such a table, or a group of  components contained within another lightweight container, such as a JPanel. Program       Program Source import javax.swing.JFrame; import javax.swing.JPanel; import javax.swing.JButton; import javax.swing.JScrollPane; … Read more…

JTabbedPane

The JTabbedPane control is available in Swing. This component appears as a group of folders in a file cabinet. Each folder has a title. When a user selects a folder, its contents become visible. Only one of the folders can be selected at a time. void addTab ( String str, Component comp) Here, str is … Read more…