04-28-2012 04:37 AM
I am trying to find how to control the selected are of a field so when the field is selected only a portion of the field is highlighted. I can't find any way to do this other then embed a small field inside a largr non-selectable field.
Any suggestions on how to do this?
Thanks!
Solved! Go to Solution.
04-28-2012 05:20 AM
Hi crispoyz,
You can override fields drawfocus method to do this.
Try with this code. This is a sample code just for understanding.
class CustomField extends Field
{
int width = 100;
int height = 100;
String _text;
public CustomField(String text)
{
super(Field.FOCUSABLE);
_text = text;
}
protected void layout(int width, int height) {
setExtent(getPreferredWidth(), getPreferredHeight());
}
protected void drawFocus(Graphics graphics, boolean on)
{
if(on)
{
graphics.setColor(Color.GREEN);
graphics.fillRect(20, 10, getPreferredWidth()-50, getPreferredHeight()-30);
graphics.setColor(Color.RED);
graphics.drawText(_text, (width - getFont().getAdvance(_text))/2,(height - getFont().getHeight())/2);
}
}
protected void paint(Graphics graphics) {
graphics.setColor(Color.RED);
graphics.drawRoundRect(0, 0, getPreferredWidth(), getPreferredHeight(), 20, 20);
graphics.drawText(_text, (width - getFont().getAdvance(_text))/2,(height - getFont().getHeight())/2);
}
public int getPreferredWidth() {
// TODO Auto-generated method stub
return width;
}
public int getPreferredHeight() {
// TODO Auto-generated method stub
return height;
}
}
Thanks.