Class org.aswing.JComboBox

Description

A component that combines a button or editable field and a drop-down list. The user can select a value from the drop-down list, which appears at the user's request. If you make the combo box editable, then the combo box includes an editable field into which the user can type a value.

JComboBox use a JList to be the drop-down list, so of course you can operate list to do some thing.

By default JComboBox can't count its preffered width accurately like default JList, you have to set its preffered size if you want. Or you make a not shared cell factory to it. see ListCellFactory and JList for details.

See Also

Field Index

ON_ACT

Inherited from Container

Inherited from Component

Inherited from EventDispatcher

Method Index

new JComboBox()
addActionListener(), getEditor(), getItemAt(), getItemCount(), getListCellFactory(), getMaximumRowCount(), getModel(), getPopupList(), getSelectedIndex(), getSelectedItem(), getUI(), getUIClassID(), hidePopup(), isEditable(), isPopupVisible(), setEditable(), setEditor(), setEnabled(), setListCellFactory(), setListData(), setMaximumRowCount(), setModel(), setPopupVisible(), setSelectedIndex(), setSelectedItem(), setUI(), showPopup(), updateUI()

Inherited from Container

Inherited from Component

Inherited from EventDispatcher

Constructor Detail

JComboBox

public function JComboBox(listData:Object)

JComboBox(listData:Array)
JComboBox(model:ListModel)
JComboBox()

Field Detail

ON_ACT

static public ON_ACT:String
When a selection has been made or a editing stoped.
onActionPerformed Event{source:DefaultComboBoxEditor}

Method Detail

setUI

public function setUI(ui:ComboBoxUI):Void

Description copied from Component

Sets the look and feel delegate for this component. Component subclasses generally override this method to narrow the argument type. For example, in JSlider:

 public void setUI(SliderUI newUI) {
     super.setUI(newUI);
 }
  

Additionally Component subclasses must provide a getUI method that returns the correct type. For example:

 public SliderUI getUI() {
     return (SliderUI)ui;
 }
 

Overrides

setUI() in org.aswing.Component

updateUI

public function updateUI():Void

Description copied from Component

Resets the UI property to a value from the current look and feel. Component subclasses must override this method like this:

   public void updateUI() {
      setUI((SliderUI)UIManager.getUI(this);
   }
  

Overrides

updateUI() in org.aswing.Component

getUIClassID

public function getUIClassID():String

Description copied from Component

Returns the UIDefaults key used to look up the name of the org.aswing.plaf.ComponentUI class that defines the look and feel for this component. Most applications will never need to call this method. Subclasses of Component that support pluggable look and feel should override this method to return a UIDefaults key that maps to the ComponentUI subclass that defines their look and feel.

Overrides

getUIClassID() in org.aswing.Component

getUI

public function getUI():ComboBoxUI

addActionListener

public function addActionListener(func:Function, obj:Object):Object

addChangeListener(func:Function)
addChangeListener(func:Function, obj:Object)

The ActionListener will receive an ActionEvent when a selection has been made. If the combo box is editable, then an ActionEvent will be fired when editing has stopped.

Return

the listener added.

See Also

getPopupList

public function getPopupList():JList

Returns the popup list that display the items.

setMaximumRowCount

public function setMaximumRowCount(count:Number):Void

Sets the maximum number of rows the JComboBox displays. If the number of objects in the model is greater than count, the combo box uses a scrollbar.

Parameters

countan integer specifying the maximum number of items to display in the list before using a scrollbar

getMaximumRowCount

public function getMaximumRowCount():Number

Returns the maximum number of items the combo box can display without a scrollbar

Return

an integer specifying the maximum number of items that are displayed in the list before using a scrollbar

getListCellFactory

public function getListCellFactory():ListCellFactory

Return

the cellFactory for the popup List

setListCellFactory

public function setListCellFactory(newFactory:ListCellFactory):Void

This will cause all cells recreating by new factory.

Parameters

newFactorythe new cell factory for the popup List

setEditor

public function setEditor(anEditor:ComboBoxEditor):Void

Sets the editor used to paint and edit the selected item in the JComboBox field. The editor is used both if the receiving JComboBox is editable and not editable.

Parameters

anEditorthe ComboBoxEditor that displays the selected item

getEditor

public function getEditor():ComboBoxEditor

Returns the editor used to paint and edit the selected item in the JComboBox field.

Return

the ComboBoxEditor that displays the selected item

setEditable

public function setEditable(aFlag:Boolean):Void

Determines whether the JComboBox field is editable. An editable JComboBox allows the user to type into the field or selected an item from the list to initialize the field, after which it can be edited. (The editing affects only the field, the list item remains intact.) A non editable JComboBox displays the selected item in the field, but the selection cannot be modified.

Parameters

aFlaga boolean value, where true indicates that the field is editable

isEditable

public function isEditable():Boolean

Returns true if the JComboBox is editable. By default, a combo box is not editable.

Return

true if the JComboBox is editable, else false

setEnabled

public function setEnabled(b:Boolean):Void

Enables the combo box so that items can be selected. When the combo box is disabled, items cannot be selected and values cannot be typed into its field (if it is editable).

Parameters

ba boolean value, where true enables the component and false disables it

Overrides

setEnabled() in org.aswing.Component

setListData

public function setListData(ld:Array):Void

set a array to be the list data, but array is not a List Mode. So when the array content was changed, you should call updateListView to update the JList(the list for combo box).But this is not a good way, its slow. So suggest you to create a ListMode eg. VectorListMode, When you modify ListMode, it will automatic update JList.

See Also

setModel

public function setModel(m:ListModel):Void

Set the list mode to provide the data to JList.

See Also

getModel

public function getModel():ListModel

Return

the model of this List

showPopup

public function showPopup():Void

Causes the combo box to display its popup window.

See Also

hidePopup

public function hidePopup():Void

Causes the combo box to close its popup window.

See Also

setPopupVisible

public function setPopupVisible(v:Boolean):Void

Sets the visibility of the popup, open or close.

isPopupVisible

public function isPopupVisible():Boolean

Determines the visibility of the popup.

Return

true if the popup is visible, otherwise returns false

setSelectedItem

public function setSelectedItem(anObject:Object):Void

Sets the selected item in the combo box display area to the object in the argument. If anObject is in the list, the display area shows anObject selected.

If anObject is not in the list and the combo box is uneditable, it will not change the current selection. For editable combo boxes, the selection will change to anObject.

ON_ACT (addActionListener())events added to the combo box will be notified when this method is called.

Parameters

anObjectthe list object to select; use null to clear the selection

getSelectedItem

public function getSelectedItem():Object

Returns the current selected item.

If the combo box is editable, then this value may not have been in the list model.

Return

the current selected Object

See Also

setSelectedIndex

public function setSelectedIndex(anIndex:Number):Void

Selects the item at index anIndex.

Parameters

anIndexan integer specifying the list item to select, where 0 specifies the first item in the list and -1 or greater than max index indicates empty selection

getSelectedIndex

public function getSelectedIndex():Number

Returns the first item in the list that matches the given item. The result is not always defined if the JComboBox allows selected items that are not in the list. Returns -1 if there is no selected item or if the user specified an item which is not in the list.

Return

an integer specifying the currently selected list item, where 0 specifies the first item in the list; or -1 if no item is selected or if the currently selected item is not in the list

getItemCount

public function getItemCount():Number

Returns the number of items in the list.

Return

an integer equal to the number of items in the list

getItemAt

public function getItemAt(index:Number):Object

Returns the list item at the specified index. If index is out of range (less than zero or greater than or equal to size) it will return undefined.

Parameters

indexan integer indicating the list position, where the first item starts at zero

Return

the Object at that list position; or undefined if out of range