Here is a custom editfield that i created . It has options to render the text.
Code:
package customfields;
import net.rim.device.api.system.Characters;
import net.rim.device.api.ui.Color;
import net.rim.device.api.ui.DrawStyle;
import net.rim.device.api.ui.Graphics;
import net.rim.device.api.ui.Keypad;
import net.rim.device.api.ui.component.BasicEditField;
import net.rim.device.api.ui.component.EditField;
import net.rim.device.api.ui.container.HorizontalFieldManager;
import net.rim.device.api.ui.container.VerticalFieldManager;
public class CustomEditField extends HorizontalFieldManager implements DrawStyle
{
private int _managerWidth = 0;
private int _managerHeight = 0;
private BasicEditField _editField = null;
HorizontalFieldManager _hfm = null;
boolean _optionalFlag = false;
Graphics _graphics = null;
int _autoScrollPos = 0;
int _scrollAmount = 0;
VerticalFieldManager _scollableManager = null;
String OPTIONAL_STRING = "(Optional)";
long _fieldStyle = 0;
/**
* @param width width of the field
* @param height height of the field
* @param optional wether this is an optional field or not
* @param scrollPos scrolling position index. 1 for 1st field. 2 for second field
* @param scollableManager vertical field manager where the fields are laying.
* @param fieldStyle preffered field style.
*/
public CustomEditField(int width, int height, boolean optional,int scrollPos, VerticalFieldManager scollableManager ,long fieldStyle)
{
super(HorizontalFieldManager.NO_HORIZONTAL_SCROLL);
_managerWidth = width;
_managerHeight = height;
_optionalFlag = optional;
_autoScrollPos = scrollPos;
_scrollAmount = _autoScrollPos * 40;
_scollableManager = scollableManager;
_fieldStyle = fieldStyle;
_hfm = new HorizontalFieldManager(HorizontalFieldManager.HORIZONTAL_SCROLL);
_editField = new BasicEditField("", "", 50,FIELD_HCENTER | EditField.NO_NEWLINE | _fieldStyle)
{
public void paint(Graphics graphics)
{
if(getText().trim().length() > 0)
{
_graphics = graphics;
graphics.setColor(Color.BLACK);
if(isFocus())
{
graphics.drawText(getText(), 0, 0);
}
else
{
graphics.drawText(getText(), 0, 0,DrawStyle.ELLIPSIS,_managerWidth);
}
}
else if(_optionalFlag)
{
graphics.setColor(Color.GRAY);
graphics.drawText(OPTIONAL_STRING, 0, 0);
if(!isFocus() && getText().trim().length() > 0)
{
graphics.drawText(getText(), 0, 0,DrawStyle.ELLIPSIS,_managerWidth);
}
}
}
protected boolean keyDown(int keycode, int time)
{
char keyChar = Keypad.map(keycode);
if(keyChar == Characters.ENTER && _scollableManager != null)
{
_scollableManager.setVerticalScroll(_scrollAmount);
}
return super.keyDown(keycode, time);
}
};
_hfm.add(_editField);
add(_hfm);
}
public void setEditable(boolean editable)
{
_editField.setEditable(editable);
}
public void setMaxChar(int maxChar)
{
_editField.setMaxSize(maxChar);
}
public void setFocus()
{
_editField.setFocus();
}
public void focusChangeNotify(int arg0)
{
if(!_editField.isFocus() )
{
if(_editField.getText().trim().length() > 0)
{
_hfm.deleteAll();
_editField.setText(_editField.getText().trim());
_hfm.add(_editField);
}
}
else
{
if(_scollableManager != null)
_scollableManager.setVerticalScroll(_scrollAmount);
}
super.focusChangeNotify(arg0);
}
public void sublayout(int width, int height)
{
if (_managerWidth == 0)
_managerWidth = 260;
if (_managerHeight == 0)
_managerHeight = 25;
super.sublayout(_managerWidth, _managerHeight);
setExtent(_managerWidth, _managerHeight);
}
protected void paint(Graphics graphics)
{
graphics.clear(0, 0, _managerWidth, _managerHeight);
super.paint(graphics);
}
public String getTextString()
{
return _editField.getText();
}
public void setTextString(String text)
{
_editField.setText(text);
}
} You can use this for multiple purpose. Sample image of the field is attached.