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?
I think BB way is not to style components, but extend them - so the solution could be:
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);
Related
As I'm novice in Blackberry/Java development, I don't know how to use "telugu" font in my Blackberry application. Please give an example.
see the difference between three simulators
9300-OS6 not displaying
9790-os7 displays only in this device .
9900-os7 even OS7 it is not displaying.
import net.rim.device.api.system.*;
import net.rim.device.api.ui.*;
import net.rim.device.api.ui.container.*;
import net.rim.device.api.ui.component.*;
import java.util.*;
public class FontLoadingDemo extends UiApplication
{
public static void main(String[] args)
{
FontLoadingDemo app = new FontLoadingDemo();
app.enterEventDispatcher();
}
public FontLoadingDemo()
{
pushScreen(new FontLoadingDemoScreen());
}
}
class FontLoadingDemoScreen extends MainScreen
{
public FontLoadingDemoScreen()
{
setTitle("Font Loading Demo");
LabelField helloWorld = new LabelField("Hello World");
if (FontManager.getInstance().load("Myfont.ttf", "MyFont", FontManager.APPLICATION_FONT) == FontManager.SUCCESS)
{
try
{
FontFamily typeface = FontFamily.forName("MyFont");
Font myFont = typeface.getFont(Font.PLAIN, 50);
helloWorld.setFont(myFont);
}
catch (ClassNotFoundException e)
{
System.out.println(e.getMessage());
}
}
add(helloWorld);
}
}
Source: http://docs.blackberry.com/en/developers/deliverables/11958/Load_and_use_a_custom_font_899948_11.jsp
I have two Radiobutton and on one RadioButton click i want to hide editfield, so please can anyone help me.
Thanks, In advance.
Perhaps you could try using Managers to delete and add fields. Try:
package mypackage;
import net.rim.device.api.ui.Field;
import net.rim.device.api.ui.FieldChangeListener;
import net.rim.device.api.ui.component.BasicEditField;
import net.rim.device.api.ui.component.RadioButtonField;
import net.rim.device.api.ui.component.RadioButtonGroup;
import net.rim.device.api.ui.container.MainScreen;
import net.rim.device.api.ui.container.VerticalFieldManager;
public final class MyScreen extends MainScreen {
private BasicEditField bef = new BasicEditField();
private VerticalFieldManager manager = new VerticalFieldManager();
private RadioButtonGroup rbg = new RadioButtonGroup();
public MyScreen() {
setTitle("Hide Control Demo");
manager.add(bef);
add(manager);
RadioButtonField rbf1 = new RadioButtonField("Option 1", rbg, true);
RadioButtonField rbf2 = new RadioButtonField("Option 2", rbg, false);
add(rbf1);
add(rbf2);
rbf2.setChangeListener(new FieldChangeListener() {
public void fieldChanged(Field field, int context) {
if (bef.getManager() != null && rbg.getSelectedIndex() == 1) {
manager.delete(bef);
System.out.println("Option 2 Selected");
}
}
});
}
}
Try this it will work
package com.hb;
import net.rim.device.api.ui.Field;
import net.rim.device.api.ui.FieldChangeListener;
import net.rim.device.api.ui.UiApplication;
import net.rim.device.api.ui.component.EditField;
import net.rim.device.api.ui.component.RadioButtonField;
import net.rim.device.api.ui.component.RadioButtonGroup;
import net.rim.device.api.ui.container.HorizontalFieldManager;
import net.rim.device.api.ui.container.MainScreen;
import net.rim.device.api.ui.container.VerticalFieldManager;
public class Startup extends UiApplication{
public static void main(String[] args) {
Startup start=new Startup();
start.enterEventDispatcher();
}
public Startup() {
pushScreen(new screen());
}
}
class screen extends MainScreen implements FieldChangeListener
{
RadioButtonField field1,field2;
private EditField edit1;
private VerticalFieldManager edit_mgr=null;
public screen() {
HorizontalFieldManager hr=new HorizontalFieldManager();
RadioButtonGroup g=new RadioButtonGroup();
field1=new RadioButtonField("edit", g,true);
field1.setChangeListener(this);
hr.add(field1);
field2=new RadioButtonField("no edit", g,false);
field2.setChangeListener(this);
hr.add(field2);
add(hr);
edit_mgr=new VerticalFieldManager();
edit1=new EditField();
edit1.setEditable(true);
edit_mgr.add(edit1);
add(edit_mgr);
}
public void fieldChanged(Field field, int context) {
if(field==field1){
synchronized (UiApplication.getEventLock()) {
edit1.setEditable(true);
}
}else if(field==field2){
synchronized (UiApplication.getEventLock()) {
edit1.setEditable(false);
}
}
}
}
Let's say I have a typical Blackberry app:
public class MyApp extends UiApplication {
public static void main(String[] args) {
MyApp app = new MyApp();
app.enterEventDispatcher();
}
public MyApp() {
pushScreen(new MyScreen());
}
}
and already at the beginning I notice, that a mandatory condition is missing (wrong Display dimensions; missing SD card; some IT policy; etc.)
Is there a way to display a short and quick message to the user (in the form of Alert/Status/Dialog/whatever) and exit straight away - without/before instantiating a complex Screen/registering Acceleration listeners/installing complex CleanupRunnable?
I've tried Status.show(), Dialog.alert() - they do not work (RuntimeException "pushModalScreen called by a non-event thread"):
public class MyScreen extends MainScreen {
public MyScreen() {
if (Display.getWidth() < 400) {
Status.show("Goodbye");
return;
}
}
}
Instead of direct invocation use invokeLater. Sample is below:
Application.getApplication().invokeLater(new Runnable() {
public void run() {
Dialog.inform("Your message here...");
}
});
Instead of Dialog.inform you may use Status.show()
Actually the following is better, than what's suggested by Rafael - because it doesn't have the ugly white screen underneath. Here is my complete example MyApp.java:
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.*;
import net.rim.device.api.system.*;
import net.rim.device.api.ui.image.*;
public class MyApp extends UiApplication {
public static void main(String[] args) {
MyApp app = new MyApp();
app.enterEventDispatcher();
}
public MyApp() {
pushScreen(new MyScreen());
}
}
class MyScreen extends MainScreen implements DialogClosedListener {
Dialog myDialog = new Dialog(Dialog.OK, "Goodbye!", 0, Bitmap.getPredefinedBitmap(Bitmap.EXCLAMATION), Dialog.GLOBAL_STATUS);
public MyScreen() {
// XXX just some condition, like wrong dimensions or IT policy
if (Display.getWidth() > 40) {
myDialog.setDialogClosedListener(this);
Application.getApplication().requestBackground();
Application.getApplication().invokeLater(new Runnable() {
public void run() {
myDialog.show();
}
});
return;
}
// XXX heavy stuff to be skipped
}
public void dialogClosed(Dialog dialog, int choice) {
if (dialog == myDialog) {
System.out.println("XXX exiting XXX");
System.exit(1);
}
}
}
I am writing a small demo program to display a message box in to run in blackberry. As soon as I click the OK button on the dialog, it throws me a JVM Error 104, uncaught:runtimeexception. Any help please? Here is the code :
import net.rim.device.api.ui.FieldChangeListener;
import net.rim.device.api.ui.UiApplication;
import net.rim.device.api.ui.component.*;
import net.rim.device.api.ui.container.HorizontalFieldManager;
import net.rim.device.api.ui.container.MainScreen;
import net.rim.device.api.ui.container.VerticalFieldManager;
import net.rim.device.api.ui.*;
import net.rim.device.api.ui.container.*;
public class My_First_App extends UiApplication
{
public static void main(String[] args)
{
My_First_App theApp = new My_First_App();
theApp.enterEventDispatcher();
}
public My_First_App()
{
pushScreen(new My_First_AppScreen());
}
}
final class My_First_AppScreen extends MainScreen
{
public My_First_AppScreen()
{
super();
HorizontalFieldManager _fieldmanager;
_fieldmanager = new HorizontalFieldManager();
/* declare one label to how the application title */
LabelField applicationtitle = new LabelField("Demo",LabelField.ELLIPSIS | LabelField.USE_ALL_WIDTH);
ButtonField _pairMe = new ButtonField("PairMe");
FieldChangeListener listenerPairMe = new FieldChangeListener() {
public void fieldChanged(Field field, int context){
Dialog.alert("You clicked the button!");
}
};
/*set the title*/
add(_fieldmanager);
setTitle(applicationtitle);
_fieldmanager.add(_pairMe);
_pairMe.setChangeListener(listenerPairMe);
}
public boolean onClose()
{
Dialog.alert("Goodbye!");
System.exit(0);
return true;
}
}
create a new workspace. It's related to Eclipse, not to your code
My application extends the ui.Manager class. Is it possible to enter the app without using the enterEventDispatcher. As it needs me to inherit the Application/UiApplication to do that.
Is multiple inheritance the solution?
Multiple inheritance is rather not possible in Java. So is it about using interfaces?
You should really inherit App from UiApplication (if it has some UI) or from Application (if it's background app, service).
If you have some Manager extension, place it into Screen extension.
Like this:
import net.rim.device.api.system.Display;
import net.rim.device.api.ui.UiApplication;
import net.rim.device.api.ui.container.HorizontalFieldManager;
import net.rim.device.api.ui.container.MainScreen;
public class CenterButtonPanelApp extends UiApplication {
public CenterButtonPanelApp() {
pushScreen(new Scr());
}
public static void main(String[] args) {
CenterButtonPanelApp app = new CenterButtonPanelApp();
app.enterEventDispatcher();
}
}
class Scr extends MainScreen {
public Scr() {
CenterButtonPanel centerPanel = new CenterButtonPanel();
add(centerPanel);
}
}
class CenterButtonPanel extends HorizontalFieldManager {
int mWidth = Display.getWidth();
public CenterButtonPanel() {
super(FIELD_HCENTER);
}
public int getPreferredWidth() {
return mWidth;
}
protected void sublayout(int maxWidth, int maxHeight) {
super.sublayout(mWidth, maxHeight);
setExtent(mWidth, maxHeight);
}
}