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
Trusted Contributor
Posts: 178
Registered: ‎02-20-2011
My Device: 8700
My Carrier: at&t
Accepted Solution

NO_NEWLINE

Hi everyone,

 

here is my code:

 

        class HrefField extends LabelField {
            public HrefField(String hyperlinkLabel) {
                super(hyperlinkLabel,FOCUSABLE);
                Font font = Font.getDefault();
                setFont(font.derive(Font.derive(Font.UNDERLINED));
           
       

                add(new RichTextFieldHome:,TextField.NO_NEWLINE))
                add(new HrefFieldhttp://www.Hom.co)
                    protected boolean navigationClick(int status,int time) {
                        bs = Browser.getDefaultSession();
                        bs.displayPage("http://www.Home.com");
                        return true;
                    }
                });


How to display them in one line?

 

thank in advance!

# I tried to change the world, but I couldn't find the source code #



Highlighted
Developer
Posts: 202
Registered: ‎04-19-2011
My Device: Blackberry Bold 9780
My Carrier: TAM

Re: NO_NEWLINE

how about using horizontalFieldManager?

Trusted Contributor
Posts: 178
Registered: ‎02-20-2011
My Device: 8700
My Carrier: at&t

Re: NO_NEWLINE

I tried ,but is even odd

Thank you for your advance all the same.

# I tried to change the world, but I couldn't find the source code #



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

Re: NO_NEWLINE

NO_NEWLINE is just an instruction to the Text Field to ignore new line characters.  It actually has no effect on the positioning of the Field.  And in fact it does not stop the Field going over more than 1 line.  Its only effect is on 'new line' characters.

 

The 1st trap you have fallen into here is that RichTextField's will always grab the whole width of the Manager they are added into.  A LabelField does not.

 

The 2nd trap you have fallen into is assuming a VerticalFieldManager will layout anything horizontally.  It won't.

 

So change your RichTextField to a LabelField, add it and the HrefField to a HorizontalFieldManager, and then add the lot to your screen.  That should work. 

 

There is lot of very useful information in these places:

 

http://supportforums.blackberry.com/t5/Java-Development/Create-custom-fields/ta-p/444962

 

http://supportforums.blackberry.com/t5/Java-Development/Create-a-custom-layout-manager-for-a-screen/...

 

http://supportforums.blackberry.com/t5/Java-Development/MainScreen-explained/ta-p/606644

Developer
Posts: 2,268
Registered: ‎07-08-2009
My Device: various
My Carrier: various

Re: NO_NEWLINE

In fact, RichTextField does have a method of limiting its width - USE_TEXT_WIDTH (specific for RichTextField only, doesn't exist for TextField etc.). Useful when you want to decorate the text inside (not possible with LabelField).

 

----------------------------------------------------------
please click 'Accept Solution' on posts that provide the solution to the question you've posted. Don't say "Thanks", press 'Like' button instead!
Developer
Posts: 19,636
Registered: ‎07-14-2008
My Device: Not Specified

Re: NO_NEWLINE

Thanks for that arkadyz, didn't know that!  kudos to you!

 

So for the original poster, you can use a RichTextField making sure that you set USE_TEXT_WIDTH.

 

Here is a sample....

 

        RichTextField rtf = new RichTextField("test", RichTextField.USE_TEXT_WIDTH);
        RichTextField rtf2 = new RichTextField("test2", RichTextField.USE_TEXT_WIDTH);
        HorizontalFieldManager hfm = new HorizontalFieldManager();
        hfm.add(rtf);
        hfm.add(rtf2);
        this.add(hfm);

Trusted Contributor
Posts: 178
Registered: ‎02-20-2011
My Device: 8700
My Carrier: at&t

Re: NO_NEWLINE

Thank you for all of your advices,thus I made a progress on it.

But the new is "http://wap.Mobile.com" below disappeared!

 

                VerticalFieldManager vfm=new VerticalFieldManager();
                HorizontalFieldManager hfm1=new HorizontalFieldManager();
                hfm1.add(new RichTextField("Home: ",RichTextField.USE_TEXT_WIDTH));
                hfm1.add(new HrefField(" http://www.Home.com"){
                    protected boolean navigationClick(int status,int time) {
                        bs = Browser.getDefaultSession();
                        bs.displayPage("http://www.Home.com");
                        return true;
                    }
                });
                vfm.add(hfm1);
                HorizontalFieldManager hfm2=new HorizontalFieldManager();
                hfm2.add(new RichTextField("Mobile: ",RichTextField.NO_NEWLINE));
                hfm2.add(new HrefField(" http://wap.Mobile.com"){
                    protected boolean navigationClick(int status,int time) {
                        bs = Browser.getDefaultSession();
                        bs.displayPage("http://wap.Mobile.com");
                        return true;
                    }
                });
                vfm.add(hfm2);
                add(vfm);

I also tried this witout vfm:

hfm1.add();

hfm1.add();

add(hfm1);

hfm2.add();

hfm2.add();

add(hfm2);

# I tried to change the world, but I couldn't find the source code #



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

Re: NO_NEWLINE

The code works for me, using the class definition you supplied in the first post, after correcting this line:

setFont(font.derive(Font.derive(Font.UNDERLINED));

Is there something else in HrefField that we are not aware of?

 

Try your code with two LabelFields.  Also, I think if you replace your HrefField with an ActiveRichtextField, you might get the linking that you require for free!  Give that a try too.

 

If you still have no luck, can you tell us what OS and SImulator you are testing on, and can we have all your code, including a 'cut down HrefField, cut down to the minimum that displays the problem.