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: 84
Registered: ‎07-22-2011
My Device: bb-9550,bb-9700
My Carrier: bb developer

Print text from right to left

hi all,

 

I need to print the text from right to left using editfield do anyone have any idea.

For example

In edit field when we enter the text it prints from left to right (for eg: abcdefgh....cursor)

now i need to print it from right to left(for eg:  cursor........hgfedcba)    

 

any help  plzzzz

 

Thanks in advance

 

                              

 
Developer
Posts: 84
Registered: ‎07-22-2011
My Device: bb-9550,bb-9700
My Carrier: bb developer

Re: Print text from right to left

any help plzzzz


Thanks in advance
Developer
Posts: 541
Registered: ‎05-17-2009
My Device: Not Specified

Re: Print text from right to left

I'm not aware of anything in the API that will allow you to write right to left like that. It's possible to achieve this by creating a custom class that extends field. If you need more direction with this, I would search for "create custom field" in the forum.

 

Scott

Developer
Posts: 84
Registered: ‎07-22-2011
My Device: bb-9550,bb-9700
My Carrier: bb developer

Re: Print text from right to left

hi superdirt,

Thanks for the reply

Here im posting the code where in the text gets printed from the right but it is scrolling to the left and it is not changing the position of the cursor,im setting the position of the cursor still no change

class CustomEditField extends Manager
{
private int _fieldHeight = 0;
private int _fieldWidth = 0;
private long _alignment;
private Font _font = Font.getDefault();
private AlignableEditField _editField;


public CustomEditField(String initialValue, int maxNumChars, long style)
{
super(NO_VERTICAL_SCROLL | NO_VERTICAL_SCROLLBAR);
_alignment = (style & BasicEditField.FIELD_HALIGN_MASK & BasicEditField.FIELD_TRAILING);

_editField = new AlignableEditField(null, initialValue, maxNumChars, style)
{
protected void onFocus(int direction)
{
setCursorPosition(0);
};
};
add(_editField);
}

protected void paint(Graphics g) {
super.paint(g);
}

public int getPreferredWidth() {
return _fieldWidth;
}

public int getPreferredHeight() {
return _font.getHeight();
}

public String getText() {
return _editField.getText();
}

public void setFont(Font value) {
_font = value;
_editField.setFont(_font);
}

protected void sublayout(int width, int height) {
if (_fieldWidth == 0) {
_fieldHeight = height;
_fieldWidth = width;
setExtent(width, _fieldHeight);
}

int textWidth = _editField.getPreferredWidth();

layoutChild(_editField, textWidth, _fieldHeight);

if (_alignment == FIELD_RIGHT)
{
setPositionChild(_editField, getPreferredWidth() - textWidth-10, 0);
}
else if (_alignment == FIELD_HCENTER)
{
setPositionChild(_editField,
(getPreferredWidth() - textWidth) / 2, 0);
}
else
{
// FIELD_LEFT
setPositionChild(_editField, 0, 0);
}
}

private void layoutEditField() {
sublayout(_fieldWidth, _fieldHeight);
}

private class AlignableEditField extends BasicEditField
{
public AlignableEditField(String label, String initialValue,int maxNumChars, long style)
{
super(label, initialValue, maxNumChars, style);
}

public int getPreferredWidth()
{
return Math.max(_font.getAdvance(getText()), _font.getAdvance('0'))+ _font.getAdvance(' ');
}

protected boolean keyChar(char key, int status, int time)
{
boolean result = super.keyChar(key, status, time);
layoutEditField();
return result;
}
/* protected void onFocus(int direction)
{
setCursorPosition(0);
super.onFocus(direction);
}*/


}

}
}


iam unable to understand what are the changes that need to b done.

any help...

Thanks in advance.
Developer
Posts: 285
Registered: ‎08-26-2011
My Device: 9900
My Carrier: Not Specified

Re: Print text from right to left

Do you want like Arabic style or if any person enter data the we have to show it in reverse order; 

=================================================================================
Feel free to click LIKE button if the solution helps you;
--
Regards,

ALI SHAIK.
Developer
Posts: 84
Registered: ‎07-22-2011
My Device: bb-9550,bb-9700
My Carrier: bb developer

Re: Print text from right to left

when we enter the data as well as when we display the data both should be in arabic style.


Thanks
Developer
Posts: 84
Registered: ‎07-22-2011
My Device: bb-9550,bb-9700
My Carrier: bb developer

Re: Print text from right to left

reply plzzzz need it urgently....
Developer
Posts: 30
Registered: ‎02-02-2012
My Device: 9780
My Carrier: DU. UAE

Re: Print text from right to left

Set the style of Editfield as Field.FIELD_LEADING | DrawStyle.LEADING  . It will automatically display the arabic and hebrew language in right to left mode.