Java AWT cause Choice box to open automatically

Hi I have a choice box that when I click it I calculate what items the user can choose. Unfortunately because I add and remove choices it makes my choice close itself so I have to open it twice. Is there a way to send an event to the choice box so it opens itself without me clicking on it?

thanks,
Roland

Can you determine what needs to be in the Choice box before it gains the focus?

Presumably the content of the Choice box is dependent upon user input to some other Component?
If so, fill the Choice as soon as this dependent data is entered. (rather than when user tries to focus the Choice box)

I can determine what needs to be in the choice box. It shows weapons for my game and removes the weapons I can’t afford. I only want to check when the user wants to pick a weapon because the calculation is slow

I calculate the weapons on gain focus. Therefore the choice must open then I make it close with the add/remove. Is there a way to change the contents just before the choice opens?

If the calculation is really that slow, surely you don’t want to be doing it in the Event Dispatch Thread anyway?

its not too slow but I only want to calculate it when I open the choice box

Why? You should calculate it as items change, then just keep it cached (if it’s causing you speed problems).

how do i keep it cached?

Example:


ArrayList<String> choices = new ArrayList<String>();

if (foo)
{
    choices.add("You can do this.");
}
if (foo2)
{
    choices.add(Or you can do this.");
}
//etc.

By cache I mean find the values whenever and then just store them for future use. This is typically a good idea when a certain operation is performing observable slowdown.

cool, thanks.