#8 Editable BComboBox doesn't generate key events


A BComboBox, editable or not, generates a ValueChangedEvent
when a value is selected from its menu. An editable BComboBox
also generates that event when the return key is pressed.

But I need to know as each letter is typed into the BComboBox. I
can even catch events by Object.class, but no key events are ever


  • Peter Eastman

    Peter Eastman - 2004-11-01

    Logged In: YES

    This happens because an editable JComboBox is actually a compound
    component. That is, it's a Container with multiple Components inside it.
    I'll think about this and see if I can figure out a reasonable workaround...

  • Peter Johnson

    Peter Johnson - 2005-01-26

    Logged In: YES

    I've been looking at this problem for another reason. It really seems
    that BComboBox does not get many events, because most of the awt
    events are targeted at the BComboBox's JComboBox's "editor"

    I can get the events I need (in particular for me, focus events) by getting
    that component and listening to it directly. But of course, it would be
    much more generally useful to have BComboBox do this for you already.
    I have considered a couple of different ways of going about this. Every
    solution so far must assume that the JComboBox's editor
    (ComboBoxEditor interface) is actually a BasicComboBoxEditor

    1. Have BComboBox implement listeners for events on its editor
    component and dispatch Buoy events directly.
    2. Modify EventAdaptor so that it can be constructed with--and use--a
    JComponent that is different that the Widget's defined JComponent, then
    have BComboBox override addEventLink/removeEventLink to use a
    second EventAdaptor for that editor component.
    3. Modify EventAdaptor so that it can be constructed with an array of
    additional JComponents for which to register listeners, all for the same
    Widget. BComboBox will still have to override addEventLink/
    removeEventLink to construct its EventAdaptor differently that most
    other Widgets.
    4. Add a JComponent[] getComponents() method to Widget and have
    EventAdaptor use that to set up listeners for each returned component.
    Normally getComponents() would just return the single JComponent used
    by the Widget, but this would give Widgets such as BComboBox to tell
    the outside world about its auxiliary components.

    I'm leaning towards #4 or possibly #3. I'd be interested in hearing
    other's thoughts.

  • Nobody/Anonymous

    I solved the problem of getting events from the editor by doing the following:

    Create a class MyComboBoxEditor derived from BasicComboBoxEditor:

    public class MyComboBoxEditor extends BasicComboBoxEditor
    BTextField textField;

    protected JTextField createEditorComponent()
    textField = new BTextField();
    return textField.getComponent();

    public BTextField getTextField()
    return textField;

    To add events, try the following:
    BComboBox comboBox = new BComboBox();
    MyComboBoxEditor cbEditor = new MyComboBoxEditor();
    comboBox.getComponent().setEditor( cbEditor );
    cbEditor.getTextField().addEventLink( eventType, target, method );

    This is somewhat simplified from my actual code, but I think it includes the essential elements.


Get latest updates about Open Source Projects, Conferences and News.

Sign up for the SourceForge newsletter:

JavaScript is required for this form.

No, thanks