CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 2 of 2
  1. #1
    Guest

    JComboBox and Tab key events

    I have a JComboBox and am having problems adding KeyListeners to it. I
    know about the compound component and
    have tried adding it to the following:

    1. The JComboBox itself.
    2. The JComboBox button
    3. The JComboBox CellRendererPane
    4. The JComboBox editor component

    None of these seem to work. When I set the keylistener for the editor
    component I get some key events but not the
    tabs. I am aware of
    overriding isManagingFocus for the JComboBox but the editor component
    doesn't seem to have this method to
    override.

    I really need to have this work if anyone has any info that would help
    me, please let me know.

    Lance



  2. #2
    Join Date
    Sep 1999
    Location
    Chandler, AZ
    Posts
    1

    Re: JComboBox and Tab key events

    Ok well I finally figured out a way to get this to work.

    I had to basically create my own MetalComboBoxUI and override
    the createArrowButtonMethod to override the isManagingFocus method
    for the MetalComboBoxButton. Then when I make my JComboBox, I set
    the UI to the MetalComboBoxUI if the Metal L&F is in effect.

    I've included some sample code to explain in case anyone else comes
    across the problem and needs a kludge.

    // First override the UI to get to the ArrowButton
    MetalComboBoxUI mcbUI = new MetalComboBoxUI() {
    protected JButton createArrowButton() {
    JButton button = new MetalComboBoxButton( this.comboBox,
    new MetalComboBoxIcon(),
    this.comboBox.isEditable() ? true : false,
    this.currentValuePane,
    this.listBox ){
    public boolean isManagingFocus() {
    return true;
    }
    };
    button.setMargin( new Insets( 0, 1, 1, 3 ) );
    return button;
    }

    };





Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured