Ad
Ad
Ad
Tag

list awt or util

Browsing

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.

public synchronized String[] getItems();

public synchronized String[] getItems() method returns the string items in the List.

This method returns the string items in the List.

public Dimension getMinimumSize();

public Dimension getMinimumSize() method returns the minimum dimensions of the List.

This method returns the minimum dimensions of the List.

public Dimension getMinimumSize (int rows);

public Dimension getMinimumSize (int rows) method returns the minimum dimensions of a List of the given size.

This method returns the minimum dimensions of a List of the given size.

Parameter
rows – Number of rows within List to size.

public Dimension getPreferredSize();

public Dimension getPreferredSize() method returns the preferred dimensions of the List.

This method returns the preferred dimensions of the List.

public Dimension getPreferredSize (int rows);

public Dimension getPreferredSize (int rows) method returns the preferred dimensions of a List of the given size.

This method returns the preferred dimensions of a List of the given size.

Parameter
rows – Number of rows within List to size.

public int getRows();

public int getRows() method returns the number of rows requested to be displayed in List.

This method returns the number of rows requested to be displayed in List.

public synchronized int getSelectedIndex();

public synchronized int getSelectedIndex() method returns the position of currently selected entry, or -1 if nothing is selected, or if multiple entries are selected.

This method returns the position of the currently selected entry, or -1 if nothing is selected, or if multiple entries are selected.

public synchronized int[] getSelectedIndexes();

public synchronized int[] getSelectedIndexes() method returns an array whose elements are the indices of the currently selected entries.

This method returns an array whose elements are the indices of the currently selected entries.

public synchronized String getSelectedItem();

public synchronized String getSelectedItem() method returns the currently selected entry as a String, or null if nothing is selected, or if multiple entries are selected.

This method returns the currently selected entry as a String, or null if nothing is selected, or if multiple entries are selected.

public synchronized String[] getSelectedItems();

public synchronized String[] getSelectedItems() method returns an array of strings whose elements are the labels of the currently selected entries.

This method returns an array of strings whose elements are the labels of the currently selected entries.

public Object[] getSelectedObjects();

public Object[] getSelectedObjects() method returns an array of strings whose elements are the labels of the currently selected entries.

This method returns an array of strings whose elements are the labels of the currently selected entries.

public int getVisibleIndex();

public int getVisibleIndex() method returns the last index from a call to makeVisible().

This method returns the last index from a call to makeVisible().

public boolean isIndexSelected(int index);

public boolean isIndexSelected(int index) method checks to see if a particular entry is currently selected.

This method returns true if index selected, false otherwise.

Parameter
index – Position to check.

public boolean isMultipleMode();

public boolean isMultipleMode() method returns true if multiple selection is allowed, false otherwise.

This method returns true if multiple selection is allowed, false otherwise.

public boolean isSelected (int index);

public boolean isSelected (int index) method checks to see if a particular entry is currently selected. Replaced by isIndexSelected(int).

This method returns true if index selected, false otherwise.

Parameter
index – Position to check.

public synchronized void makeVisible (int index);

public synchronized void makeVisible (int index) method ensures an item is displayed on the screen.

Parameter
index – Position to make visible on screen.

public Dimension minimumSize();

public Dimension minimumSize() method returns the minimum dimensions of the List. Replaced by getMinimumSize().

This method returns the minimum dimensions of the List. Replaced by getMinimumSize().

public Dimension minimumSize (int rows);

public Dimension minimumSize (int rows) method returns the minimum dimensions of a List of the given size. Replaced by getMinimumSize(int).

This method returns the minimum dimensions of a List of the given size. Replaced by getMinimumSize(int).

Parameter
rows – Number of rows within List to size.

public Dimension preferredSize();

public Dimension preferredSize() method returns the preferred dimensions of the List. Replaced by getPreferredSize().

This method returns the preferred dimensions of the List. Replaced by getPreferredSize().

public Dimension preferredSize (int rows);

public Dimension preferredSize (int rows) method returns the preferred dimensions of a List of the given size. It is replaced by getPreferredSize(int).

This method returns the preferred dimensions of a List of the given size.

Parameter
rows – Number of rows within List to size.

public synchronized void remove (int position);

public synchronized void remove (int position) method removes a single entry from the List.

Parameter
position – Position of item to remove.

public synchronized void remove (String item);

public synchronized void remove (String item) method removes a single entry from the List.

Parameter
item – Item to remove.

public void removeActionListener (ActionListener l);

public void removeActionListener (ActionListener l) method remove an action event listener.

Parameter
l – One of this List’s ActionListeners.

public synchronized void removeAll();

public synchronized void removeAll() method removes all items from the List.

public void removeItemListener (ItemListener l);

public void removeItemListener (ItemListener l) method removes the specified ItemListener so it will not receive ItemEvent objects from this List.

Parameter
l – The listener to be removed.

public void removeNotify();

public void removeNotify() method destroys the peer of the List.

public synchronized void replaceItem (String newItem, int index);

public synchronized void replaceItem (String newItem, int index) method replaces the contents at a particular position with a new entry.

Parameter
newItemLabel for entry to add.
index – Position of entry to replace.

public synchronized void select (int position);

public synchronized void select (int position) method makes the given entry the selected one for the List.

Parameter
position – Position to make selected entry.

public synchronized void setMultipleMode (boolean b);

public synchronized void setMultipleMode (boolean b) method changes List’s selection mode based upon flag.

Parameter
b – true to enable multiple selections; false to disable multiple selections.

public synchronized void setMultipleSelections (boolean value);

public synchronized void setMultipleSelections(boolean value) method changes List’s selection mode based upon flag. Replaced by setMultipleMode(boolean).

Parameter
value – true to enable multiple selections; false to disable multiple selections.

protected String paramString();

protected String paramString() method is a Helper method for toString() to generate string of current settings.

This method returns a String with current settings of List.

protected void processActionEvent (ActionEvent e);

protected void processActionEvent (ActionEvent e) method accepts action events for processing. Normally, this method is called by processEvent().

Parameter
e – The action event to process.

protected void processEvent (AWTEvent e);

protected void processEvent (AWTEvent e) method accepts a low-level AWTEvents for processing.

Parameter
e – The action event to process.

protected void processItemEvent (ItemEvent e);

protected void processItemEvent (ItemEvent e) method accepts item events for processing. Normally, this method is called by processEvent().
This method returns
Parameter
e – The action event to process.