List Class In AWT in Java

0
104
Spread the love
  • 23
  • 34
  • 56
  • 35
  •  
  •  
  •  
  • 12
  •  
  •  
    160
    Shares

List Class In AWT in Java

List class is a Component that graphically displays a list of strings. The list is scrollable if necessary. The constructor takes optional arguments that specify the number of visible rows in the list and whether the selection of more than one item is ured allowed. The various instance methods allow strings to be added and removed from the list and allow the selected item or items to be queried.

The List is a Component that provides a scrollable list of choices to select from. A-List can be in one of two modes: single selection mode, in which only one item may be selected at a time; and multiple selection mode, in which several items may be selected at one time. A list does not necessarily display all of the choices at one time; one of the constructors lets you specify the number of choices to display simultaneously. Although the changes in 1.1 are extensive, almost all of them can be boiled down to (1) using the 1.1 event model, and (2) standardizing method names (e.g. set/get pairs).

The definition of List Class is given as

public class java.awt.List extends ava.awt.Component implements java.awt.ItemSelectable{
// Public Constructors
public List();
public List(int rows);
public List(int rows, boolean multipleMode);
// Public Instance Methods
public void add(String item);
public synchronized void add(String item, int index);
public synchronized void addActionListener(ActionListener al);
public void addItem(String item);
public synchronized void addItem(String item, int index);
public synchronized void addItemListener(ItemListener il);// From ItemSelectable
public void addNotify();// Overrides Component
public boolean allowsMultipleSelections();
public synchronized void clear();
public int countItems();
public synchronized void delItem(int position);
public synchronized void delItems(int start, int end);
public synchronized void deselect(int index);
public String getItem(int index);
public int getItemCount();
public synchronized String [ ] getItems();
public Dimension getMinimumSize(int rows);
public Dimension getMinimumSize();// Overrides Component
public Dimension getPreferredSize(int rows);
public Dimension getPreferredSize();// Overrides Component
public int getRows();
public synchronized int getSelectedIndex();
public synchronized int [ ] getSelectedIndexes();
public synchronized String getSelectedItem();
public synchronized String [ ] getSelectedItems();
public Object [ ] getSelectedObjects();// From ItemSelectable
public int getVisibleIndex();
public boolean is IndexSelected(int index);
public boolean isMultipleMode();
public boolean isSelected(int index);
public synchronized void makeVisible(int index);
public Dimension minimumSize(int rows);
public Dimension minimumSize();// Overrides Component
public Dimension preferredSize(int rows);
public Dimension preferredSize();// Overrides Component
public synchronized void remove(String item);
public synchronized void remove(int position);
public synchronized void removeActionListener(ActionListener al);
public synchronized void removeAll(); 
public synchronized void removeItemListener(ItemListener il) //From ItemSelectable ();
public void removeNotify()// Overrides Component
public synchronized void replaceItem(String newValue, int index);
public synchronized void select(int index);
public synchronized void set MultipleMode(boolean b);
public synchronized void setMultipleSelections(boolean b);//protected method
protected String paramString();// Overrides Component
protected void processActionEvent(ActionEvent e);
protected void processEvent(AWTEvent e);// Overrides Component
protected void processItemEvent(ItemEvent e);
}

The details of the class structure are given as follows:

public List();

public List() constructs a List object in single-selection mode.

public List (int rows);

public List (int rows) constructs a List object with the specified number of rows, in single-selection mode.

Parameter
rows – Requested number of rows to display.

public List (int rows, boolean multipleSelections);

public List (int rows, boolean multipleSelections) constructs a List object.

Parameter
rows – Requested number of rows to display.
multipleSelections – true to allow multiple selections; false to select one item at a time.

public void add (String item);

public void add (String item) method adds a new entry to the available choices.

Parameter
item – Text for entry to add.

public synchronized void add (String item, int index);

public synchronized void add (String item, int index) method adds a new entry to the available choices at the designated position.

Parameter
item – Text for entry to add.
index – Position at which to add entry; the first entry has an index of zero.

public void addActionListener (ActionListener l);

public void addActionListener (ActionListener l) method adds a listener for the action event.

Parameter
l – An object that implements the ActionListener interface.

public void addItem (String item);

public void addItem (String item) method is replaced by add(String).

Parameter
item – Text for entry to add.

public synchronized void addItem (String item, int index);

public synchronized void addItem (String item, int index) method is replaced by add(String, int).

Parameter
item – Text for entry to add.
index – Position at which to add entry; the first entry has an index of zero.

public void addItemListener (ItemListener l);

public void addItemListener (ItemListener l) method adds a listener for the ItemEvent objects this List fires off.

Parameter
l – The listener to be added.

public void addNotify();

public void addNotify() method creates List’s peer.

public boolean allowsMultipleSelections();

public boolean allowsMultipleSelections() method returns true if multi-selection active, false otherwise. Replaced by isMultipleMode().

This method returns true if multi-selection active, false otherwise. Replaced by isMultipleMode().

public synchronized void clear();

public synchronized void clear() method clears all the entries out of the List. Replaced by removeAll().

public int countItems();

public int countItems() method returns the number of items in the List. Replaced by getItemCount().

This method returns the number of items in the List. Replaced by getItemCount().

public synchronized void delItem (int position);

public synchronized void delItem (int position) method removes a single entry from the List. Replaced by remove(int) and remove(String).

Parameter
position – Position of item to delete.

public synchronized void delItems(int start, int end);

public synchronized void delItems (int start, int end) method removes a set of entries from the List.

Parameter
start – Starting position of entries to delete.
end – Ending position of entries to delete.

public synchronized void deselect (int index);

public synchronized void deselect(int index) method deselects the entry at the designated position, if selected.

Parameter
index – Position to deselect.

public String getItem(int index);

public String getItem(int index) method returns a String for entry at given position.

This method returns a String for entry at given position.

Parameter
index – Position of entry to get.

public int getItemCount();

public int getItemCount() method returns the number of items in the List.

This method returns the number of items in the List.

Don't miss out!
Subscribe To Newsletter

Receive top technical news, lesson ideas, travel tips and more!

Invalid email address
Give it a try. You can unsubscribe at any time.

Spread the love
  • 23
  • 34
  • 56
  • 35
  •  
  •  
  •  
  • 12
  •  
  •  
    160
    Shares

LEAVE A REPLY

Please enter your comment!
Please enter your name here