2

I have tried it overriding paint() method inside my own class which extends LabelField, but I ignore if there is another simpler way.

My code:

protected void paint(Graphics graphics) {
    int previousColor = graphics.getColor();
    graphics.setColor(0xFFFFFF);
    graphics.drawText(getText(), 2, -2);
    graphics.setColor(previousColor);
    super.paint(graphics);
}

What I want to achieve is this:

enter image description here

EDIT: The answer by Abhisek produces the following result, in case anyone is interested:

enter image description here

Community
  • 1
  • 1
Pablo
  • 2,834
  • 5
  • 25
  • 45

2 Answers2

3

If Abhishek's answer does not work, you can try to do it directly in the paint method. It's easy, just paint it once in the bg color, then paint it again over it (a few pixels down and left the previous text) in the fg color. Something like this:

    protected void paint(Graphics graphics) {
        graphics.setColor(0xFFFFFF);
        graphics.drawText(getText(), 2, 0);
        graphics.setColor(0x000000);
        graphics.drawText(getText(), 0, 2);
    }

Notice how you need 2 extra pixels of height and width, so probably you'll have to override getPreferredWidth, getPreferredHeight and/or layout.

Community
  • 1
  • 1
Mister Smith
  • 27,417
  • 21
  • 110
  • 193
0

A stab in the dark, but try deriving a font using Font.derive(style, height, units, aAntialiasMode, aEffects), pass Font.DROP_SHADOW_RIGHT_EFFECT in the aEffects parameter and apply it to the field in question.

Do tell us if it works; I haven't used it since it's undocumented!

Filip Radelic
  • 26,607
  • 8
  • 71
  • 97
Abhishek
  • 473
  • 3
  • 12
  • Thank you for your suggestion. Using `Font.DROP_SHADOW_RIGHT_EFFECT` produces in fact a text shadow, but in the same color as the text and in bottom-right direction only. – Pablo Dec 14 '12 at 12:24