jbcl.control Package
java.lang.Object +----java.awt.Component +----java.awt.Choice +----com.borland.jbcl.view.ChoiceView +----com.borland.jbcl.control.ChoiceControl
Variables Constructors Properties Methods Event Listeners
Implements AccessListener, ColumnAware, DataChangeListener, DataSetAware, 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.
A ChoiceControl
is typically used in the following ways:
Column
of a DataSet
.
The pre-defined choices come from setting the items
property. Once the items are set, you can
add items to the control using 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 store the selected item into a Column
of a DataSet
, set the columnName
and dataSet
properties of the ChoiceControl
component. The selected item is copied into the specified Column
of the DataSet's
current row.
Column
of a DataSet
.
Call
the setItems(DataSet,String)
method, including the DataSet
and columnName
containing data values you want displayed in the ChoiceControl
as parameters. This creates the ChoiceControl's
items from that data. For more information on using this method, see its description.
Note: The UI Designer does not add this line of code automatically; you have to manually add this to your program.
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 com.borland.jbcl.control.*;
import com.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
samples 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(String newColumnName)The
Column
that the selected item of the ChoiceControl
will be written to. You must also set the dataSet
property to specify the DataSet
that this Column
is part of.
This property does not populate the ChoiceControl
. To populate a ChoiceControl
with data values stored in a DataSet
, use the setItems(DataSet,String)
method.
public DataSet getDataSet() public void setDataSet(DataSet newDataSet)The
DataSet
object that the selected item of the ChoiceControl
will be written to. You must also set the columnName
property which specifies which Column
in the DataSet
to write to.
This property does not populate the ChoiceControl
. To populate a ChoiceControl
with data values stored in a DataSet
, use the setItems(DataSet,String) method.
public void setModel(SingletonModel sm)
Checks for a recursive model, then calls com.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(DataSet dataSet, String columnName)
Populates the ChoiceControl
using the strings from the specified column of the specified DataSet
. In order to display the DataSet's
data, the DataSet
must be open (usually explicitly) before calling this method.
Parameters:
dataSet
DataSet
to use to populate the ChoiceControl
.
columnName
dataSet
to use.
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 addInputMethodListener(java.awt.event.InputMethodListener ) public synchronized void removeInputMethodListener(java.awt.event.InputMethodListener )
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(SingletonModelListener listener) public void removeModelListener(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 )
public synchronized void addPropertyChangeListener(java.beans.PropertyChangeListener ) public synchronized void removePropertyChangeListener(java.beans.PropertyChangeListener )