pivot-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Chris Bartlett <cbartlet...@gmail.com>
Subject Re: avoid sheet close by press "Enter"
Date Wed, 18 Aug 2010 06:57:51 GMT

The key press handling for Sheets occurs in the
org.apache.pivot.wtk.skin.terra.TerraSheetSkin class.

The following code snippet shows a quick way to do this for a particular
Sheet instance.

sheet.getComponentKeyListeners().add(new ComponentKeyListener.Adapter() {
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;

// Listen for a new key code
if (keyCode == Keyboard.KeyCode.EQUALS) {
// Code taken from
// org.apache.pivot.wtk.skin.terra.TerraSheetSkin#keyPressed
return true;

// Ignore all other keyCode values
return false;

This works, but you have to add listeners for each Sheet instance.

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);

In order to use a custom skin, you would also need to create a custom Sheet
class (which just extends Sheet, but doesn't add any extra behaviour).
Then you need to associate the custom Sheet class with the custom Skin class
in the Theme.

This can be done programmatically
Theme.getTheme().set(CustomSheet.class, CustomSheetSkin.class);
or by defining your own Theme (which can be based on Terra)

The 2nd option allows you to encapsulate the desired Sheet behaviour into
easily re-useable components.



On 18 August 2010 10:57, <kenjiang@sz.murata.com.cn> wrote:

> Hi All,
> Do you know how to avoid the sheet  component close by press "Enter".
> I would like use have to press the custom button to close the sheet.
> Many thanks.
> Best regards,
> Ken Jiang
> *******************************************
> Murata Electronics Trading  (Shenzhen) Co.,Ltd
> Tel:86-755-82847251
> E-mail:kenjiang@sz.murata.com.cn <E-mail%3Akenjiang@sz.murata.com.cn>
> *******************************************

View raw message