1

How to make a blackberry BitmapField non-focusable in runtime? I want make it dimmed based on a certain event.

Nate
  • 31,017
  • 13
  • 83
  • 207
  • You can see [my solution to this similar question here](http://stackoverflow.com/a/11488638/119114). The code I show **will** dim the field when it's disabled. My example is for the [BitmapButtonField class](https://github.com/blackberry/Samples-for-Java/blob/master/Advanced%20UI/src/com/samples/toolkit/ui/component/BitmapButtonField.java), but it should work the same for a normal `BitmapField`, too. – Nate Apr 30 '13 at 21:54

2 Answers2

1

Extend the BitmapField to override the isFocusable() method like this:

public class FocusableBitmapField extends BitmapField {
    //Default value depending on whether you want it that way.
    private boolean focusable = true;

    public boolean isFocusable() {
        return focusable;
    }

    public boolean setFocusable(boolean focusable) {
        this.focusable = focusable;
    }
}
Adwiv
  • 1,283
  • 9
  • 15
1

Most of times this works:

field.setEditable(false);

You can also create a non-focusable field by passing the style flag Field.NON_FOCUSABLE or Field.FOCUSABLE to the constructor, but once instantiated you cannot change it's focusable state. Even if you could, then the field won't look "dimmed" or "disabled", but simply the focus will jump to the next focusable field after it. An example of this are non-focusable label fields.

UPDATE: This would work for built in fields like EditFields, Checkbox, RadioButtons, etc. In your case, this does not work since a BitmapField is not "editable", it's a read only field. You can make a trick like @adwiv answer shows, but the "disabled" or gray overlay you'll have to implement it yourself.

Mister Smith
  • 27,417
  • 21
  • 110
  • 193
  • +1. In [this similar question](http://stackoverflow.com/a/11488638/119114), I show how you can simply check if the field is editable/focusable in an overridden `paint()` method, and adjust the field's alpha to *dim* it. – Nate Apr 30 '13 at 21:56