1

I've been able to style a LabelField with bold, underlined and italic text, but I have yet to find a way to specify strikethrough text. I haven't been able to find any documentation that it's supported or any other examples where it's implemented. Is it possible to display text with a strikethrough effect in BlackBerry OS 4.6 or 4.7?

1 Answers1

2

I think BB way is not to style components, but extend them - so the solution could be:

enter image description here

package mypackage;

import net.rim.device.api.ui.*;
import net.rim.device.api.ui.component.*;
import net.rim.device.api.ui.container.*;
import net.rim.device.api.ui.decor.*;

public class MyApp extends UiApplication {
    public static void main(String[] args) {
        MyApp myApp = new MyApp();
        myApp.enterEventDispatcher();
    }

    public MyApp () {
        pushScreen(new MyScreen());
    }    
}

class MyScreen extends MainScreen {
    public MyScreen() {
        LabelField myLabel = new LabelField("Strike me") {
            protected void paint(Graphics g) {
                super.paint(g);

                int w = getFont().getAdvance(getText());
                g.drawLine(0, getHeight()/2, w, getHeight()/2);
            }
        };
        add(myLabel);
    }
}

UPDATE: You could also use

Font f = g.getFont();
Font s = f.derive(Font.STRIKE_THROUGH);
g.setFont(s);
Alexander Farber
  • 21,519
  • 75
  • 241
  • 416