Click to See Complete Forum and Search --> : JComboBox and Tab key events


September 28th, 1999, 02:46 PM
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

LRZone
September 28th, 1999, 03:47 PM
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;
}

};