jbcl.control Package 

ChoiceControl component

java.lang.Object
   +----java.awt.Component
           +----java.awt.Choice
                   +----com.borland.jbcl.view.ChoiceView
                           +----com.borland.jbcl.control.ChoiceControl

About the ChoiceControl component

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:

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.


ChoiceControl variables

Variables implemented in java.awt.Component

ChoiceControl constructors

ChoiceControl properties

*Read-only properties **Write-only properties

Properties implemented in this class

Properties implemented in com.borland.jbcl.view.ChoiceView

Properties implemented in java.awt.Choice

Properties implemented in java.awt.Component

Properties implemented in java.lang.Object

ChoiceControl methods

Methods implemented in this class

Methods implemented in com.borland.jbcl.view.ChoiceView

Methods implemented in java.awt.Choice

Methods implemented in java.awt.Component

Methods implemented in java.lang.Object

ChoiceControl event listeners


ChoiceControl constructors

ChoiceControl()

  public ChoiceControl()

Constructs a ChoiceControl with default property values.


ChoiceControl properties

columnName

 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.

dataSet

 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.

model

 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.


ChoiceControl methods

addNotify()

  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()

setItems(com.borland.dx.dataset.DataSet, java.lang.String)

  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
The (open) DataSet to use to populate the ChoiceControl.
columnName
The column of dataSet to use.

ChoiceControl event listeners

This component is a source for the following event sets.

component

 public synchronized void addComponentListener(java.awt.event.ComponentListener )
 public synchronized void removeComponentListener(java.awt.event.ComponentListener )

focus

 public synchronized void addFocusListener(java.awt.event.FocusListener )
 public synchronized void removeFocusListener(java.awt.event.FocusListener )

inputMethod

 public synchronized void addInputMethodListener(java.awt.event.InputMethodListener )
 public synchronized void removeInputMethodListener(java.awt.event.InputMethodListener )

item

 public synchronized void addItemListener(java.awt.event.ItemListener )
 public synchronized void removeItemListener(java.awt.event.ItemListener )

key

 public synchronized void addKeyListener(java.awt.event.KeyListener )
 public synchronized void removeKeyListener(java.awt.event.KeyListener )

model

 public void addModelListener(SingletonModelListener listener)
 public void removeModelListener(SingletonModelListener listener)

mouse

 public synchronized void addMouseListener(java.awt.event.MouseListener )
 public synchronized void removeMouseListener(java.awt.event.MouseListener )

mouseMotion

 public synchronized void addMouseMotionListener(java.awt.event.MouseMotionListener )
 public synchronized void removeMouseMotionListener(java.awt.event.MouseMotionListener )

propertyChange

 public synchronized void addPropertyChangeListener(java.beans.PropertyChangeListener )
 public synchronized void removePropertyChangeListener(java.beans.PropertyChangeListener )