Yes, overriding the keyPressed() method works, because it allows the caller to 
prevent the base class from receiving the event.

On Aug 18, 2010, at 8:14 AM, Chris Bartlett wrote:

> 
> 
> On 18 August 2010 19:02, Greg Brown <[email protected]> wrote:
> 
> > The following code snippet shows a quick way to do this for a particular 
> > Sheet instance.
> >
> > sheet.getComponentKeyListeners().add(new ComponentKeyListener.Adapter() {
> > @Override
> > public boolean keyPressed(Component component, int keyCode, KeyLocation 
> > keyLocation) {
> > final Sheet sheet = (Sheet) component;
> >
> > // Block the Enter key press behaviour
> > if (keyCode == Keyboard.KeyCode.ENTER) {
> > // No-op, but consume the event
> > return true;
> > }
> > ...
> > });
> 
>  This actually doesn't work. Consuming an event simply stops its propagation 
> up the component hierarchy. It doesn't prevent other listeners on the same 
> component from receiving the event.
> 
> Of course - I was mixing up my scenarios.  Apologies for any confusion.
> Am I right in thinking that the above code should work if it is set on a 
> subclass of TerraSheetSkin, as that would receive the event first and be able 
> to consume it?
> 
> 

Reply via email to