|
|
Classification: |
Java |
Category: |
AWT |
Created: |
11/27/2001 |
Modified: |
01/28/2002 |
Number: |
FAQ-0754 |
Platform: |
Symbian OS v6.0 |
|
Question: Why does my Choice list take control of the top CBA button and what can I do about it?
Answer: On getting the focus a Choice component takes control of the first CBA button, setting its label to "Change", and only releases
it when defocussed. There is nothing the developer can do to prevent this behaviour as it is part of the native implementation
of AWT Choice Components. Selecting the "Change" button from the CBA allows the user to scroll through the items of the Choice
list. An item is selected by selecting "OK" from the CBA. At this stage the Choice list is collapsed, however the Choice component
still retains control of the top button, with the focus remaining on the Choice item.
In some circumstances the developer may wish to regain control of the top CBA button. To do this it is necessary to explicitly
change focus to the underlying Container or some other Component that is not a Choice. Control of the top button will then
be relinquished by the Choice and the top CBA button will return to the state specified for the Container to which the CBA
group was added.
For instance, this can be done in the itemStateChanged(...) method of an ItemListener associated with the Choice list.
class ChoiceTest extends CFrame implements CBAListener, ItemListener { private CBAHandler cba; // Handles the CBA buttons private Choice choice = new Choice();
ChoiceTest() { choice.add("One"); ... choice.addItemListener(this); add(choice, "Center");
show();
/** Set up a CBA handler */ cba = new CBAHandler(this); cba.setText(EikCommandButtonGroup.BUTTON1,"One"); cba.setText(EikCommandButtonGroup.BUTTON2,"Two"); cba.setText(EikCommandButtonGroup.BUTTON3,"Three"); cba.setText(EikCommandButtonGroup.BUTTON4,"Quit");
cba.activate(); }
public void itemStateChanged(ItemEvent ie) { Choice choice = (Choice)ie.getItemSelectable(); //Do something with selected Item
//Return focus to underlying Component this.requestFocus(); }
public void cbaActionPerformed(CBAEvent cbae) { if(cbae.getID()== EikCommandButtonGroup.BUTTON4) System.exit(0); } }
As a general rule, when using Choices any critical control (such as "Done" or "Quit") that must remain available to the user
should not use the top CBA button.
|
|
|