Showing posts with label list controls constructors. Show all posts
Showing posts with label list controls constructors. Show all posts

Wednesday, 5 March 2014

AWT CONTROLS:Lists control

The List represents a list of text items............ 

using lists


         The List represents a list of text items. The list can be configured to that user can choose either one item or multiple items.The List provides a compact,multiple-choice ,scrolling selection list.Unlike the choice object,which shows only the single selected item in the menu,aList object can be constructed to show any number of choices in the visible window.Itcan also be constructed to allow multiple selections.

List provides these constructors:


  •  List()

              Creates a new scrolling list. Initially there are no visible lines, and only one item can be selected from the list. 

  •  List(int numRows)

             Creates a new scrolling list initialized with the specified number of visible lines. By default, multiple selections are not allowed.Parameter,rows specified by the number of items to show.

  •  List(int numRows,boolean multipleMode)

             Creates a new scrolling list initialized to display the specified number of rows. If the value of multipleMode is true, then the user can select multiple items from the list. If it is false, only one item at a time can be selected.Parameters,numRows specified by the number of items to show and multipleMode,if true, then multiple selections are allowed; otherwise, only one item can be selected at a time .

Lists provides these methods:


  • add(String item) :Adds the specified item to the end of scrolling list.

           syntax:
                void add(String item) 

  • add(String item, int index) :Adds the specified item to the the scrolling list at the position indicated by the index

          syntax:
         void add(String item, int index) 

  • getSelectedIndex():Gets the index of the selected item on the list,