Symbian
Symbian OS Library

FAQ-0722 When I repopulate a Choice list in an event handler and select the first index, why does the display not get refreshed?

[Index][spacer] [Previous] [Next]



 

Classification: Java Category: AWT
Created: 08/14/2001 Modified: 08/24/2001
Number: FAQ-0722
Platform: ER5, Symbian OS v6.0, Symbian OS v6.1

Question:
When I repopulate a Choice list in an event handler and select the first index, the display does not get refreshed until I activate the Choice list by clicking on it. Why is this and what can I do about it?

Answer:
This is a minor defect of Symbian's AWT implementation which can affect the situation where the first item is pre-selected in a repopulated Choice list. As the first item is automatically selected when a Choice list is repopulated, a check made in system code when the first item is explicitly selected reports that the index is already selected, so no redraw will occur until it is required for another reason, such as the Choice list being activated.

The problem can be worked around either by simply not selecting the first component explicitly, since it will be selected anyway, or else by making a call to pack() on the containing Frame to force a redraw after the Choice has been repopulated but before the first index is selected. In other words the line in red would be added to the code below.

final Choice c = new Choice();
add(c);
...
// populate c then display the UI
...
public void actionPerformed(ActionEvent e)
{
    c.removeAll();
    c.add("New Item 0");
    c.add("New Item 1");
    c.add("New Item 2");
    c.add("New Item 3");
    c.add("New Item 4");
    c.add("New Item 5");
    pack();
    c.select();...
    }