06-11-2009 02:35 PM
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?
Solved! Go to Solution.
06-11-2009 03:43 PM
Try this:
RichTextField rtf = new RichTextField("Hello World", Field.FOCUSABLE | Field.READONLY | Field.HIGHLIGHT_FOCUS);
Regards
Bikas
06-11-2009 03:48 PM
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.
06-11-2009 03:51 PM
See the KB article for formatting text in a RichTextField:
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
06-11-2009 05:53 PM - edited 06-11-2009 06:35 PM
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/mess
Regards
Bikas