public void addItem ( Object item ) { if ( item == null ) return ; for ( int i = 0 ; i < getItemCount ( ) ; i ++ ) { if ( item . equals ( getItemAt ( i ) ) ) { if ( i == 0 ) { setSelectedIndex ( 0 ) ; return ; // already there } removeItemAt ( i ) ; } } // add as first in the list insertItemAt ( item , 0 ) ; setSelectedIndex ( 0 ) ; }
Add the item to the top of the list . If it already exists move it to the top .