Hi All, Thank you for your great help.
I think attach a SheetStateListener to the sheet is proper way for this issue. Best regards, Ken Jiang ******************************************* Murata Electronics Trading (Shenzhen) Co.,Ltd Tel:86-755-82847251 E-mail:[email protected] ******************************************* From: Greg Brown <[email protected]> To: [email protected] Date: 08/18/2010 08:03 PM Subject: Re: avoid sheet close by press "Enter" Hi Ken, Escape and Enter are a platform convention for closing a sheet or dialog, so overriding their behavior may not be a good idea. However- > 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. > Another option would be to create a custom Sheet skin class that overrides the keyPressed method in TerraSheetSkin. > The code for the keyPressed method in the custom skin would be mostly the same as the above snippet, but the final return could be something like > return super.keyPressed(component, keyCode, keyLocation); This will work. You don't actually need to create a custom sheet class for this - you can simply replace the mapping for the standard Sheet class in the theme. Another option is to attach a SheetStateListener to the sheet. You can return Vote.DENY from previewSheetClose() to prevent the sheet from closing (perhaps based on the state of some property that you would set when your custom close button is pressed). G
