borland Packages Class Hierarchy jbcl.control Package Index
java.lang.Object +----java.awt.Component +----java.awt.Choice +----borland.jbcl.view.ChoiceView +----borland.jbcl.control.ChoiceControl
Variables Constructors Properties Methods Event Listeners
Implements AccessListener, ColumnAware, DataChangeListener, DataSetAware, NavigationListener, SingletonModel, SingletonModelListener, WritableSingletonModel, BlackBox, SingletonModelView, KeyListener, ImageObserver, ItemSelectable, MenuContainer, Serializable, EventListener
The ChoiceControl is a drop-down list of choices. The current selection is visible.
If the control is connected to a column in a data set through the dataSet and columnName properties, it displays the values in the specified column of the data set. In this case, ChoiceControl is a data-aware control.
If ChoiceControl is not being used as a data-aware control, the choices available come from the items property. To add items to the control, use the addItem() or add() methods. To insert an item, call insert(). To remove items, call remove() or removeAll(). The itemCount property contains the number of items in the control.
To select an item in the ChoiceControl, call the select() method. The selectedIndex property contains the index number of the selected item in the control, and the selectedItem property contains the String that represents the selected item.
When an item in the choice control is selected, events such as modelContentChanged and itemStateChanged occur. The code that you write in response to one or more of these events determines what happens with the selected item.
Example
// After selecting an animal name from the choice menu, the name appears in
// the text field.
import java.awt.*;
import java.awt.event.*;
import borland.jbcl.control.*;
import borland.jbcl.layout.*;
public class ChoiceEx {
public ChoiceEx() {
ChoiceFrame frame = new ChoiceFrame();
frame.pack();
frame.setVisible(true);
}
static public void main(String[] args) {
new ChoiceEx();
}
}
class ChoiceFrame extends DecoratedFrame {
BevelPanel bev = new BevelPanel();
ChoiceControl choiceCtrl = new ChoiceControl();
TextFieldControl textFieldControl = new TextFieldControl();
public ChoiceFrame() {
this.setTitle("Animals");
choiceCtrl.setItems(new String[] {"Koala", "Monkey", "Lark", "Puffin"});
this.add(bev);
bev.add(choiceCtrl, new XYConstraints(30, 10, -1, -1));
bev.add(textFieldControl, new XYConstraints(0, 50, 125, -1));
textFieldControl.setText("Koala");
choiceCtrl.addItemListener(new ChoiceControlItemAdapter(this));
}
void choiceControlItemStateChanged(ItemEvent itemEvent) {
textFieldControl.setText((String)choiceCtrl.get());
}
}
class ChoiceControlItemAdapter implements java.awt.event.ItemListener {
ChoiceControlItemAdapter(ChoiceFrame choiceframe) {
this.choiceframe = choiceframe;
}
ChoiceFrame choiceframe;
public void itemStateChanged(ItemEvent itemEvent) {
choiceframe.choiceControlItemStateChanged(itemEvent);
}
}
For an example that uses a ChoiceControl, see the project file Cardlayout.jpr located in the jbuilder\samples\borland\samples\jbcl\cardlayout directory of your JBuilder installation. This sample uses a CardLayout panel that is controlled by a ChoiceControl, ListControl, and TabsetControl.
public ChoiceControl()
Constructs a ChoiceControl with default property values.
public String getColumnName() public void setColumnName(java.lang.String newColumnName)Identifies a column of the specified borland.jbcl.dataset.DataSet object that contains the items displayed in the ChoiceControl. setColumnName() sets the model to SingletonDataSetManager using the specified column of the specified DataSet.
public DataSet getDataSet() public void setDataSet(borland.jbcl.dataset.DataSet newDataSet)Specifies a borland.jbcl.dataset.DataSet that contains the column that displays in the ChoiceControl.
public void setModel(borland.jbcl.model.SingletonModel sm)
Checks for a recursive model, then calls borland.jbcl.view.ChoiceView.setModel(SingletonModel), which specifies the model object required for access to a list of choices. ChoiceView requires a VectorModel object.
public void addNotify()
Calls addNotify() of java.awt.Choice to create the ChoiceControl's peer. This peer allows changing the look of the ChoiceControl without changing its functionality. Initializes the ChoiceControl if not already initialized. Opens the DataSet supplying items for this ChoiceControl.
Overrides: java.awt.Choice.addNotify()
public void setItems(borland.jbcl.dataset.DataSet dataSet, java.lang.String columnName)
Populates the ChoiceControl using the strings from the specified column of the specified DataSet.
Parameters:
public synchronized void addComponentListener(java.awt.event.ComponentListener ) public synchronized void removeComponentListener(java.awt.event.ComponentListener )
public synchronized void addFocusListener(java.awt.event.FocusListener ) public synchronized void removeFocusListener(java.awt.event.FocusListener )
public synchronized void addItemListener(java.awt.event.ItemListener ) public synchronized void removeItemListener(java.awt.event.ItemListener )
public synchronized void addKeyListener(java.awt.event.KeyListener ) public synchronized void removeKeyListener(java.awt.event.KeyListener )
public void addModelListener(borland.jbcl.model.SingletonModelListener listener) public void removeModelListener(borland.jbcl.model.SingletonModelListener listener)
public synchronized void addMouseListener(java.awt.event.MouseListener ) public synchronized void removeMouseListener(java.awt.event.MouseListener )
public synchronized void addMouseMotionListener(java.awt.event.MouseMotionListener ) public synchronized void removeMouseMotionListener(java.awt.event.MouseMotionListener )