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
Developer
Posts: 19
Registered: ‎06-11-2009
My Device: Not Specified
Accepted Solution

focusable RichTextField

How do I make a RichTextField focusable, but not editable or selectable?

 

What I want is a field that has the text formatting options of a RichTextField but behaves like a LabelField that is set to Focusable.

 

I want the whole thing to be highlighted when it gains focus.

 

Anyone have any suggestions?

Developer
Posts: 984
Registered: ‎02-10-2009
My Device: Not Specified

Re: focusable RichTextField

Try this:

 

RichTextField rtf = new RichTextField("Hello World", Field.FOCUSABLE | Field.READONLY | Field.HIGHLIGHT_FOCUS);

 

Regards

Bikas

 

Developer
Posts: 19
Registered: ‎06-11-2009
My Device: Not Specified

Re: focusable RichTextField

I tried that.

What I have is:

RichTextField entry = new RichTextField(combined, offset, attribute, fonts, RichTextField.USE_TEXT_WIDTH | RichTextField.READONLY | RichTextField.FOCUSABLE | RichTextField.HIGHLIGHT_FOCUS);

 

I get a field that isn't editable, but the cursor still enters the text field and scrolls through it. I have a list of these fields and I want the entire field to be highlighted when I scroll to it.

Highlighted
Developer
Posts: 984
Registered: ‎02-10-2009
My Device: Not Specified

Re: focusable RichTextField

See the KB article for formatting text in a RichTextField:

http://www.blackberry.com/knowledgecenterpublic/livelink.exe/fetch/2000/348583/800332/800505/800345/...

 

 

One more thing, pass the values (Field.FOCUSABLE | Field.READONLY | Field.HIGHLIGHT_FOCUS)  as the style

  RichTextField(String text, int[] offsets, byte[] attributes, Font[] fonts, long style)

 

 

Regards

Bikas

Developer
Posts: 984
Registered: ‎02-10-2009
My Device: Not Specified

Re: focusable RichTextField

[ Edited ]

Try with this:

 

RichTextField entry = new RichTextField(combined, offset, attribute, fonts, Field.FOCUSABLE | Field.READONLY )
{
XYRect focusRect;
protected void onFocus(int direction)
{
if ( focusRect == null )
{
focusRect = this.getExtent();
}
super.onFocus(direction);
}
public boolean isSelectable()
{
return false;
}
protected void drawFocus(Graphics g, boolean on)
{
if ( focusRect != null )
{
super.drawHighlightRegion(g, Field.HIGHLIGHT_FOCUS, on, 0, 0, focusRect.width, focusRect.height);
}
else
{
super.drawFocus(g, on);
}
}
public void getFocusRect(XYRect rect)
{
if ( focusRect == null )
{
super.getFocusRect(rect);
}
else
{
rect.x = 0;
rect.y = 0;
rect.width = focusRect.width;
rect.height = focusRect.height;
}
}
public int moveFocus(int amount, int status, int time)
{
return amount;
}

};

Reference link:

     http://supportforums.blackberry.com/rim/board/message?board.id=java_dev&message.id=37567

 

 

Regards

Bikas

 

Message Edited by bikas on 06-12-2009 04:35 AM