Welcome!

Welcome to the official BlackBerry Support Community Forums.

This is your resource to discuss support topics with your peers, and learn from each other.

inside custom component

Java Development

Reply
Highlighted
Super Contributor
Posts: 425
Registered: ‎01-02-2013
My Device: BOLD 9900
My Carrier: sdvsdvsd
Accepted Solution

font size

i want to set font size of my text shown in label, i have post a screen shot can anyone help me
i have set different font styles to my text but unable to set font size

picr.png

Super Contributor
Posts: 425
Registered: ‎01-02-2013
My Device: BOLD 9900
My Carrier: sdvsdvsd

Re: font size

[ Edited ]

can any one help me...????????? here is my code:

public class MyApp extends UiApplication
{
String[] iFontSize = {"5","6","7","8","9","10","11","12","13","14"};
ObjectChoiceField pickSize;

private Font font;
//Get all fonts available on the BlackBerry
private FontFamily fontFamily[] = FontFamily.getFontFamilies();

public static void main(String[] args)
{
// Create a new instance of the application and make the currently
// running thread the application's event dispatch thread.
MyApp theApp = new MyApp();
theApp.enterEventDispatcher();
}

/**
* Creates a new MyApp object
*/
public MyApp()
{


MainScreen mainScreen;

FontChangeListener fontChangeListener = new FontChangeListener();

//Set the current font to the first in the font list.
font = fontFamily[0].getFont(FontFamily.SCALABLE_FONT, 20);

Font.setDefaultFont(font);

mainScreen = new MainScreen();

//Set the title of the mainscreen.
// LabelField title = new LabelField("Font Test Example", LabelField.ELLIPSIS | LabelField.USE_ALL_WIDTH);
mainScreen.setTitle("Font Test Example");

pickSize= new ObjectChoiceField ("Select Font Size:", iFontSize,0);

ObjectChoiceField pickFont = new ObjectChoiceField("Select font:", fontFamily, 0);

pickFont.setChangeListener(null);
pickFont.setChangeListener(fontChangeListener);

mainScreen.add(pickFont);
mainScreen.add(new SeparatorField());
mainScreen.add(pickSize);

mainScreen.add(new SeparatorField());

//RichTextField that displays text in the specified colour.
RichTextField fontText = new RichTextField("The quick red fox jumps over the lazy brown dog.")
{
public void paint(Graphics graphics)
{
//Change the colour of the text in the RichTextField to green.
graphics.setColor(0x00008800);
super.paint(graphics);
}
};
mainScreen.add(fontText);

//Display the main screen
pushScreen(mainScreen);

}

//Create a custom FieldChangeListener that will change the current font
//to what is selected in the ObjectChangeField.

class FontChangeListener implements FieldChangeListener
{
public void fieldChanged(Field field, int context)
{
//If the ObjectCoiceField has changed
if (field instanceof ObjectChoiceField)
{
//Get the new font selected in the ObjectChoiceField and set the
//current font to match what is selected.

ObjectChoiceField choiceField = (ObjectChoiceField)field;
font = fontFamily[choiceField.getSelectedIndex()].getFont(FontFamily.SCALABLE_FONT,20);

Font.setDefaultFont(font);
}
}
}
}

Developer
Posts: 19,636
Registered: ‎07-14-2008
My Device: Not Specified

Re: font size

There is nothing listening to changes to your Font size choice ObjectChoiceField.  You did this for your font choice field:

pickFont.setChangeListener(fontChangeListener);

why have you not done something similar for your size picker?

 

Look at the documentation for Font derive method for help is choosing a different size font. 

Super Contributor
Posts: 425
Registered: ‎01-02-2013
My Device: BOLD 9900
My Carrier: sdvsdvsd

Re: font size

sorry, i did not paste the update code.. this is the updated, and not working.
public class MyApp extends UiApplication
{
String[] iFontSize = {"5","6","7","8","9","10","11","12","13","14"};
ObjectChoiceField pickSize;
ObjectChoiceField pickFont;
private Font font;
//Get all fonts available on the BlackBerry
private FontFamily fontFamily[] = FontFamily.getFontFamilies();

public static void main(String[] args)
{
// Create a new instance of the application and make the currently
// running thread the application's event dispatch thread.
MyApp theApp = new MyApp();
theApp.enterEventDispatcher();
}


/**
* Creates a new MyApp object
*/
public MyApp()
{

MainScreen mainScreen;

FontChangeListener fontChangeListener = new FontChangeListener();

//Set the current font to the first in the font list.
font = fontFamily[0].getFont(FontFamily.SCALABLE_FONT, 20);

Font.setDefaultFont(font);

mainScreen = new MainScreen();

//Set the title of the mainscreen.
// LabelField title = new LabelField("Font Test Example", LabelField.ELLIPSIS | LabelField.USE_ALL_WIDTH);
mainScreen.setTitle("Font Test Example");

pickSize= new ObjectChoiceField ("Select Font Size:", iFontSize,0);

pickFont = new ObjectChoiceField("Select font:", fontFamily, 0);

pickFont.setChangeListener(null);
pickFont.setChangeListener(fontChangeListener);

mainScreen.add(pickFont);
mainScreen.add(new SeparatorField());
mainScreen.add(pickSize);

pickSize.setChangeListener(null);
pickSize.setChangeListener(fontChangeListener);

mainScreen.add(new SeparatorField());

//RichTextField that displays text in the specified colour.
RichTextField fontText = new RichTextField("The quick red fox jumps over the lazy brown dog.")
{
public void paint(Graphics graphics)
{
//Change the colour of the text in the RichTextField to green.
graphics.setColor(0x00008800);
super.paint(graphics);
}
};
mainScreen.add(fontText);

//Display the main screen
pushScreen(mainScreen);

}

//Create a custom FieldChangeListener that will change the current font
//to what is selected in the ObjectChangeField.

class FontChangeListener implements FieldChangeListener
{
public void fieldChanged(Field field, int context)
{
//If the ObjectCoiceField has changed
if (field instanceof ObjectChoiceField)
{
//Get the new font selected in the ObjectChoiceField and set the
//current font to match what is selected.

ObjectChoiceField choiceField = (ObjectChoiceField)field;
font = fontFamily[choiceField.getSelectedIndex()].getFont(FontFamily.SCALABLE_FONT,
Integer.parseInt((String) pickSize.getChoice(pickFont.getSelectedIndex()).toString()),Ui.UNITS_pt);

Font.setDefaultFont(font);
}
}
}
}
Developer
Posts: 19,636
Registered: ‎07-14-2008
My Device: Not Specified

Re: font size

Change

 

Font.setDefaultFont(font);

 

to

 

fontText.setFont(font);

 

and see what happens

Super Contributor
Posts: 425
Registered: ‎01-02-2013
My Device: BOLD 9900
My Carrier: sdvsdvsd

Re: font size

i have another question, it's very urgent
i have another ObjectCoiceField which containing reference to bitmap images,i have 8 images reference to ObjectCoiceField .
now is it possible the when i select an image from object list field, that selected image will set to my background.
Developer
Posts: 19,636
Registered: ‎07-14-2008
My Device: Not Specified

Re: font size

Didn't you already ask that question?

http://supportforums.blackberry.com/t5/Java-Development/Change-bitmap-background-image-on-click/m-p/...

 

I think you might find this useful - note the section on urgent:

http://www.catb.org/esr/faqs/smart-questions.html#before

Super Contributor
Posts: 425
Registered: ‎01-02-2013
My Device: BOLD 9900
My Carrier: sdvsdvsd

Re: font size

no, that was different question, this one is with object choice field
Developer
Posts: 19,636
Registered: ‎07-14-2008
My Device: Not Specified

Re: font size

[ Edited ]

There is no real difference.  In this case just do it in the change listener, rather than navigationClick.   

Super Contributor
Posts: 425
Registered: ‎01-02-2013
My Device: BOLD 9900
My Carrier: sdvsdvsd

Re: font size

here in the pic, i have created object choiice filed but i did not know how give reference to ["first","second","third","fourth","Fifth","sixth"] Bitmap images,
i mean to say that when i click on first in ObjectChoiceField the background image will be changed of my screen, and similar to second, third and so on.. and those images are static.8530.png