05-08-2012 07:06 AM
Hello all,
I am having an custom edit field with image which i am setting in its paint background method.
My custom edit field class extends horizontal scroll as i need it. but still input is not in one line while i am setting property EditField.No_Newline.
alternatively, I added some piece of code in my paint to do so...
but its updating my MainScreen scroll ......what to do pls help...
EditField ef = (EditField)getField(0);
String entireText = ef.getText();
boolean longText = false;
String textToDraw = "";
font = getFont();
int availableWidth = width - totalHorizontalEmptySpace;
if (font.getAdvance(entireText) <= availableWidth)
{
textToDraw = entireText;
}
else
{
int endIndex = entireText.length();
for (int beginIndex = 1; beginIndex < endIndex; beginIndex++)
{
textToDraw = entireText.substring(beginIndex);
if (font.getAdvance(textToDraw) <= availableWidth)
{
longText = true;
break;
}
}
}
if (longText == true)
{
// Force the edit field display only the truncated text
ef.setText(textToDraw);
// Now let the components draw themselves
super.paint(graphics);
// Return the text field its original text
ef.setText(entireText);
}
else
{
super.paint(graphics);
}
05-08-2012 07:09 AM
05-08-2012 07:54 AM
05-08-2012 09:04 AM
HI,
VerticalFieldManager vfm = new VerticalFieldManager(this.HORIZONTAL_SCROLL | USE_ALL_WIDTH | USE_ALL_HEIGHT);
EditField e = new EditField("Username","");
vfm.add(e);
if you do use this code. Then the text will be in single line. Henceforth, you customize this as your need.
Press Like, if you find this code is helpful to you.