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
Regular Contributor
Posts: 65
Registered: ‎05-15-2011
My Device: 9700
My Carrier: Att
Accepted Solution

EditField specific text in bold

[ Edited ]

Hi,

 

I want to bold specific letters in my EditField.

 

 

public void changeToBold() {
        try {
            alphaSans = FontFamily.forName("BBAlpha Sans");
            font = alphaSans.getFont(Font.BOLD, 9, Ui.UNITS_pt);
            editField.setFont(font);
        } catch (ClassNotFoundException e) {
            Dialog.alert("alert");
        }
    }
    
    public void changeToPlain() {
        try {
            alphaSans = FontFamily.forName("BBAlpha Sans");
            font = alphaSans.getFont(Font.PLAIN, 9, Ui.UNITS_pt);
            editField.setFont(font);
        } catch (ClassNotFoundException e) {
            Dialog.alert("alert");
        }
    }

 

 

 

I add the text to the EditField from a sqlite db.

while(c1.next() && c2.next()) {
                r1 = c1.getRow();
                r2 = c2.getRow();
                temp = r2.getString(0);
         
                changeToBold();
                theText += temp;
                changeToPlain();
                theText += r.1getString(0);
            }

 

 

 

*Maybe there is a way to create a LabelField that holds the text I wnat in bold and then add it simultaneously to the EditField?

 

 

Thanks,

BlackBerry Development Advisor
Posts: 15,752
Registered: ‎07-09-2008
My Device: BlackBerry PRIV
My Carrier: Bell

Re: EditField specific text in bold

You can do this using a RichtextField.

 

Format text in a RichTextField

http://supportforums.blackberry.com/t5/Java-Development/Format-text-in-a-RichTextField/ta-p/445038

Mark Sohm
BlackBerry Development Advisor

Please refrain from posting new questions in solved threads.
Problem solved? Click the Accept As Solution button.
Found a bug? Report it using Issue Tracker
Regular Contributor
Posts: 65
Registered: ‎05-15-2011
My Device: 9700
My Carrier: Att

Re: EditField specific text in bold

Thank you very much!

 

I have a question please:

Let's say I have text like this:

A Blah Blah Blah B I was walking in The Street

 

And I want to bold only the specific letters A & B.

I have this kind of text and I want to bold only specific letters but I don't know their indexes.

How can I do it?

 

Thanks again

BlackBerry Development Advisor
Posts: 15,752
Registered: ‎07-09-2008
My Device: BlackBerry PRIV
My Carrier: Bell

Re: EditField specific text in bold

You would need to search the text in the field to find the indexes of the characters you want to make bold.

Mark Sohm
BlackBerry Development Advisor

Please refrain from posting new questions in solved threads.
Problem solved? Click the Accept As Solution button.
Found a bug? Report it using Issue Tracker
Regular Contributor
Posts: 65
Registered: ‎05-15-2011
My Device: 9700
My Carrier: Att

Re: EditField specific text in bold

Thanks but let's say that I have this text:

 

V While I was walking in the street W the birds were flying

 

If I'm looking for the index of the letter W, I'll get the index of the word "while" and then I'll get the index of the letter W itself.

That because I use indexOf(" W"); (With the space before the letter)

BlackBerry Development Advisor
Posts: 15,752
Registered: ‎07-09-2008
My Device: BlackBerry PRIV
My Carrier: Bell

Re: EditField specific text in bold

Search with a space before and after the W.
Mark Sohm
BlackBerry Development Advisor

Please refrain from posting new questions in solved threads.
Problem solved? Click the Accept As Solution button.
Found a bug? Report it using Issue Tracker
Highlighted
Regular Contributor
Posts: 65
Registered: ‎05-15-2011
My Device: 9700
My Carrier: Att

Re: EditField specific text in bold

You're right in what you say but I have some problems:

The tutorial you gave me works only if you know the specific indexes of the text you want in bold, also the range of the text and how many ranges of text you have.

 

I created 2 arrays, one handles the indexes of the letters in the entire text and the second array handles the length of each letter index, for example: A (length 1), WC(length 2).

 

I tried to run it in a loop but it doesn't work:

 Font fonts[] = new Font[2];

        int[] offset = new int[3];

        byte[] attribute = new byte[3];

 

        //Get three instances of the default font.

        //On plain, one bold and one bold and italic.

        fonts[0] = Font.getDefault();

        fonts[1] = Font.getDefault().derive(Font.BOLD);

 

        for (int i = 0; i<lettersLength; i++) {

        offset[0] = letterIndexes[i]; //handles the indexes of the letters in the entire text

        attribute[0] = 1;

        offset[1] = letterLength[i]; //handles each letter index

        }

 

 

Thank you very much for your patience