    All Packages  Class Hierarchy  This Package  Previous  Next  Index

# Class jclass.bwt.JCComboBox

    java.lang.Object
       |
       +----java.awt.Component
               |
               +----java.awt.Container
                       |
                       +----java.awt.Panel
                               |
                               +----jclass.bwt.JCContainer
                                       |
                                       +----jclass.bwt.JCComboBox

public class JCComboBox
extends JCContainer
implements KeyListener, JCListListener, JCActionListener, JCItemSelectable

JCComboBox provides the capabilities of a JCTextField and a JCList component. It allows users to perform operations like typing and pasting information, and it also provides a list of possible choices that the user can select from to complete the TextField entry.

Note that on MS-Windows, AWT currently uses a Windows ComboBox as the peer for its Choice component. JCComboBox provides this functionality on all platforms.

The list may be displayed at all times, or may only drop down when the user presses an arrow button next to the TextField (a "drop-down" ComboBox).

Behavior
If the arrow button is pressed and released, the list pops up and stays up until the user clicks an item inside it, hits RETURN, clicks outside the list, or presses ESCAPE. If an item is clicked or RETURN is hit, the item is copied to the text field.

Properties

Name | Method
--- | ---
Background | setBackground
Font | setFont
Foreground | setForeground
Items | setItems
Insets | setInsets
PreferredSize | setPreferredSize
Style | setStyle
Text | setText
UserData | setUserData
VisibleRows | setVisibleRows

Events

Class | Listener | Description
--- | --- | ---
JCActionEvent | addActionListener | Called when the ENTER key is hit
JCItemEvent | addItemListener | Cafter the user selects an item
JCComboBoxEvent | addComboBoxListener | Called before the list is displayed, and after the user has made a selection

##

actionListeners
  List of JCActionEvent listeners
BEGIN
COMBOBOX_DROPDOWN
COMBOBOX_DROPDOWN_LIST
COMBOBOX_SIMPLE
END
itemListeners
  List of JCItemEvent listeners
listeners
  List of JCComboBoxEvent listeners

##

JCComboBox()
  Creates an empty ComboBox.
JCComboBox(JCVector)
  Creates an empty ComboBox with the specified list items.
JCComboBox(JCVector, Applet, String)
  Creates a comboBox which reads parameters from the applet's HTML file.
JCComboBox(String[], String)
  Creates a comboBox with the specified items and name.

##

actionPerformed(JCActionEvent)
  If the arrow button was clicked, calls showListAction to display the list.
  If the list is displayed and the RETURN key was hit, calls setTextAction to copy the selected item to the text field.
add(String)
  Adds an item to the list.
addActionListener(JCActionListener)
  Adds the specified action listener to receive JCTextField action events.
addComboBoxListener(JCComboBoxListener)
  Adds the specified JCComboBoxEvent listener to receive events.
addItemListener(JCItemListener)
  Adds the specified item listener to receive item selection events.
addNotify()
  Creates the Panel's peer.
getButton()
  Gets the button component.
getItem(int)
  Returns the item at the specified index in the list.
getItemCount()
  Returns the number of items in the list.
getItems()
  Gets the list's values as a list of Strings.
getList()
  Gets the list component.
getParameters()
  Reads the parameter values from the HTML page using the component's applet.
getSelectedIndex()
  Returns the index of the currently selected item.
getSelectedIndexes()
  Returns an array (length 1) containing the currently selected item.
getSelectedItem()
  Returns a String representation of the current choice.
getSelectedObjects()
  Returns an array (length 1) containing the currently selected item.
getStyle()
  Gets the Style value.
getText()
  Gets the value of the text.
getTextField()
  Gets the component to be used as the data entry field.
itemStateChanged(JCItemEvent)
  JCItemListener method - no-op
keyPressed(KeyEvent)
keyReleased(KeyEvent)
keyTyped(KeyEvent)
layout()
listItemSelectBegin(JCListEvent)
  JCListListener method - no-op
listItemSelectEnd(JCListEvent)
  If the user clicked an item, calls setTextAction to copy the item to the text field.
paintInterior(Graphics)
  Draws the shadows and title.
postComboBoxEvent(int, Object)
  Posts a JCComboBoxEvent
preferredHeight()
  Gets the subclass' preferred height (default: 100).
preferredWidth()
  Gets the subclass' preferred width (default: 100).
remove(String)
  Removes the first occurrence of an item from the list.
removeActionListener(JCActionListener)
  Removes the specified action listener so it no longer receives action events.
removeAll()
  Removes all items from the list.
removeComboBoxListener(JCComboBoxListener)
  Removes the specified listener so it no longer receives JCComboBoxEvents.
removeItemListener(JCItemListener)
  Removes the specified item listener so it no longer receives item events.
select(int)
  Selects the item with the specified postion.
select(Object)
  Selects the specified item.
setItems(String[])
  Sets the list's values as a list of Strings.
setLayout(LayoutManager)
  Sets the layout manager for this container.
setStyle(int)
  Sets the style, which specifies whether the list is always displayed and whether the text field is editable.
setText(String)
  Sets the text field's value to the specified string.

  HTML param name/value: "Text"/string

setTextAction(String)
  Copies the item to the text field, after first posting a JCComboBoxEvent to allow the application to disallow the selection or change its value.
setVisibleRows(int)
  Sets the number of visible rows; if set to 0 (default), the list will attempt to resize itself so that all its items are visible.

  HTML param name/value: "VisibleRows"/int

showListAction(JCActionEvent)
  Displays the list if it is not visible.

##

COMBOBOX_SIMPLE

      public final static int COMBOBOX_SIMPLE

COMBOBOX_DROPDOWN

      public final static int COMBOBOX_DROPDOWN

COMBOBOX_DROPDOWN_LIST

      public final static int COMBOBOX_DROPDOWN_LIST

itemListeners

      protected JCVector itemListeners

  List of JCItemEvent listeners

actionListeners

      protected JCVector actionListeners

  List of JCActionEvent listeners

listeners

      protected JCVector listeners

  List of JCComboBoxEvent listeners

BEGIN

      protected final static int BEGIN

END

      protected final static int END

##

JCComboBox

      public JCComboBox()

  Creates an empty ComboBox. No parameters are read from an HTML file.

JCComboBox

      public JCComboBox(JCVector items)

  Creates an empty ComboBox with the specified list items.

JCComboBox

      public JCComboBox(String items[],
                        String name)

  Creates a comboBox with the specified items and name. No parameters are read from an HTML file.

JCComboBox

      public JCComboBox(JCVector items,
                        Applet applet,
                        String name)

  Creates a comboBox which reads parameters from the applet's HTML file.

  Parameters:
    applet - the applet whose PARAM tags are to be read
    name - if this is not null, only parameters preceded by this name are read
  See Also:
    getParameter

##

getParameters

      protected void getParameters()

  Reads the parameter values from the HTML page using the component's applet. The values will override those previously set.

  Overrides:
    getParameters in class JCContainer

getTextField

      public JCTextField getTextField()

  Gets the component to be used as the data entry field.

getList

      public JCList getList()

  Gets the list component.

getButton

      public JCArrowButton getButton()

  Gets the button component.

setText

      public synchronized void setText(String s)

  Sets the text field's value to the specified string.

  HTML param name/value: "Text"/string

getText

      public synchronized String getText()

  Gets the value of the text.

  See Also:
    setText

setItems

      public synchronized void setItems(String items[])

  Sets the list's values as a list of Strings.

getItems

      public synchronized String[] getItems()

  Gets the list's values as a list of Strings.

  See Also:
    setItems

getStyle

      public int getStyle()

  Gets the Style value.

  See Also:
    setStyle

setStyle

      public void setStyle(int v)

  Sets the style, which specifies whether the list is always displayed and whether the text field is editable. If the list is hidden, it can be displayed by pressing the arrow button or hitting the down or up arrow key. The value must be one of the following values:

       COMBOBOX_SIMPLE           list is always displayed, text field is editable
       COMBOBOX_DROPDOWN         list is hidden, text field is editable (default)
       COMBOBOX_DROPDOWN_LIST    list is hidden, text field is uneditable

  Throws: IllegalArgumentException
    If an invalid value is set

getItemCount

      public int getItemCount()

  Returns the number of items in the list.

  See Also:
    getItem

getItem

      public Object getItem(int index)

  Returns the item at the specified index in the list.

  See Also:
    getItemCount

add

      public synchronized void add(String item)

  Adds an item to the list.

  Throws: NullPointerException
    If the item's value is null.

remove

      public synchronized void remove(String item)

  Removes the first occurrence of an item from the list.

  Throws: IllegalArgumentException
    If the item doesn't exist

removeAll

      public synchronized void removeAll()

  Removes all items from the list.

  Overrides:
    removeAll in class Container
  See Also:
    remove

getSelectedItem

      public synchronized String getSelectedItem()

  Returns a String representation of the current choice.

  See Also:
    getSelectedIndex

getSelectedIndex

      public int getSelectedIndex()

  Returns the index of the currently selected item.

  See Also:
    getSelectedItem

select

      public synchronized void select(int pos)

  Selects the item with the specified postion.

  Throws: IllegalArgumentException
    If the choice item position is invalid.
  See Also:
    getSelectedItem, getSelectedIndex

select

      public synchronized void select(Object item)

  Selects the specified item.

  See Also:
    getSelectedItem, getSelectedIndex

getSelectedObjects

      public synchronized Object[] getSelectedObjects()

  Returns an array (length 1) containing the currently selected item.

  See Also:
    JCItemSelectable, getSelectedIndex

getSelectedIndexes

      public synchronized int[] getSelectedIndexes()

  Returns an array (length 1) containing the currently selected item.

  See Also:
    JCItemSelectable

setVisibleRows

      public void setVisibleRows(int v)

  Sets the number of visible rows; if set to 0 (default), the list will attempt to resize itself so that all its items are visible.

  HTML param name/value: "VisibleRows"/int

  See Also:
    setItems

addComboBoxListener

      public void addComboBoxListener(JCComboBoxListener l)

  Adds the specified JCComboBoxEvent listener to receive events.

  See Also:
    JCComboBoxEvent

removeComboBoxListener

      public void removeComboBoxListener(JCComboBoxListener l)

  Removes the specified listener so it no longer receives JCComboBoxEvents.

  See Also:
    addComboBoxListener

addActionListener

      public void addActionListener(JCActionListener l)

  Adds the specified action listener to receive JCTextField action events.

  See Also:
    JCActionEvent

removeActionListener

      public void removeActionListener(JCActionListener l)

  Removes the specified action listener so it no longer receives action events.

  See Also:
    addActionListener

addItemListener

      public void addItemListener(JCItemListener l)

  Adds the specified item listener to receive item selection events.

  See Also:
    JCItemEvent, JCItemListener

removeItemListener

      public void removeItemListener(JCItemListener l)

  Removes the specified item listener so it no longer receives item events.

preferredWidth

      protected int preferredWidth()

  Gets the subclass' preferred width (default: 100).

  Overrides:
    preferredWidth in class JCContainer

preferredHeight

      protected int preferredHeight()

  Gets the subclass' preferred height (default: 100).

  Overrides:
    preferredHeight in class JCContainer

addNotify

      public void addNotify()

  Creates the Panel's peer.

  Overrides:
    addNotify in class JCContainer

layout

      public synchronized void layout()

Overrides:
  layout in class Container

showListAction

      public void showListAction(JCActionEvent ev)

  Displays the list if it is not visible. A JCComboBoxEvent is first posted.

setTextAction

      protected void setTextAction(String value)

  Copies the item to the text field, after first posting a JCComboBoxEvent to allow the application to disallow the selection or change its value. After the value is copied, an JCItemEvent is posted.

  See Also:
    addComboBoxListener, addItemListener

postComboBoxEvent

      protected JCComboBoxEvent postComboBoxEvent(int stage,
                                                  Object value)

  Posts a JCComboBoxEvent

  Returns:
    the posted event, or null if there are no listeners
  See Also:
    addComboBoxListener, JCComboBoxEvent

itemStateChanged

      public void itemStateChanged(JCItemEvent ev)

  JCItemListener method - no-op

keyPressed

      public void keyPressed(KeyEvent ev)

keyReleased

      public void keyReleased(KeyEvent ev)

keyTyped

      public void keyTyped(KeyEvent ev)

actionPerformed

      public void actionPerformed(JCActionEvent ev)

  If the arrow button was clicked, calls showListAction to display the list.
  If the list is displayed and the RETURN key was hit, calls setTextAction to copy the selected item to the text field.

  See Also:
    showListAction, setTextAction

listItemSelectBegin

      public void listItemSelectBegin(JCListEvent ev)

  JCListListener method - no-op

listItemSelectEnd

      public void listItemSelectEnd(JCListEvent ev)

  If the user clicked an item, calls setTextAction to copy the item to the text field.

  See Also:
    setTextAction

setLayout

      public final void setLayout(LayoutManager mgr)

  Sets the layout manager for this container. This method is overridden to prevent the layout mgr from being set.

  Overrides:
    setLayout in class Container

paintInterior

      public void paintInterior(Graphics gc)

  Draws the shadows and title.

  Overrides:
    paintInterior in class JCContainer

    All Packages  Class Hierarchy  This Package  Previous  Next  Index