public synchronized void setSelectedIndex ( final int selectedIndex ) { if ( items . size ( ) <= selectedIndex || selectedIndex < - 1 ) { throw new IndexOutOfBoundsException ( "Illegal argument to ComboBox.setSelectedIndex: " + selectedIndex ) ; } final int oldSelection = this . selectedIndex ; this . selectedIndex = selectedIndex ; if ( selectedIndex == - 1 ) { updateText ( "" ) ; } else { updateText ( items . get ( selectedIndex ) . toString ( ) ) ; } runOnGUIThreadIfExistsOtherwiseRunDirect ( new Runnable ( ) { @ Override public void run ( ) { for ( Listener listener : listeners ) { listener . onSelectionChanged ( selectedIndex , oldSelection ) ; } } } ) ; invalidate ( ) ; }
Programmatically selects one item in the combo box which causes the displayed text to change to match the label of the selected index .