02-20-2013 08:31 AM
Hi,I am using CustomEditField in which i over ride paint method. Every thing is fine, but the problem which i am facing is that my typing in textfield slows down. I debug it many times and found that,it is because of paint method..Please any one give me suggestions for that..
--------------------------------------------------
class CustomEditField extends EditField
{
private boolean _focusableFlag;
private String defaultText;
public CustomEditField(String defaultText)
{
super(FIELD_HCENTER);
this.defaultText = defaultText;
}
public void setFocusable(boolean focusable){
_focusableFlag =focusable;
}
protected void layout(int width, int height)
{
width = Font.getDefault().derive(Font.BOLD, Font.getDefault().getHeight()-2).getAdvance("Trans
height = Font.getDefault().getHeight();
super.layout(width,height);
super.setExtent(width,height);
super.setFilter(MyTextFilter.get(TextFilter.NUMERI
}
protected void paint(Graphics g)
{
setBorder(BorderFactory.createRoundedBorder(new XYEdges(5,5,5,5), 0xD0D0D0, Border.STYLE_SOLID));
setBackground(BackgroundFactory.createSolidBackgro
if(super.getText().length() == 0)
{
g.setColor(0xD0D0D0);
g.drawText(defaultText, 0, 0);
g.clear();
}
g.setColor(0x484C54);
super.paint(g);
}
}
Solved! Go to Solution.
02-20-2013 08:40 AM
02-20-2013 09:22 AM
Thanx simon for your kind help,it works in my CustomEditField.. Now i have another issue,on the same screen there is header which contains 2 Fields i.e Label field and ImageButtonField.. They both have 2 paint methods.. I am confused,b/c i am not able to put my setBackground and setBorder outside the paint methods...Please help me out there...
---------------------------------------------------LockedHeaderHorizontalManager----------------------------------------------
public LockedHeaderHorizontalManager(String label)
{
super(Manager.HORIZONTAL_SCROLL | Manager.HORIZONTAL_SCROLLBAR | USE_ALL_WIDTH | USE_ALL_HEIGHT);
ButtonField bf = new ButtonField(ButtonField.CONSUME_CLICK)
{ //------Start Of Button Field
boolean _inFocus = false;
protected void layout(int width, int height)
{
super.layout(80,50);
super.setExtent(80,50);
}
public void onFocus(int direction)
{
_inFocus = true;
this.invalidate();
}
public void onUnfocus()
{
_inFocus = false;
this.invalidate();
}
protected void paint(Graphics graphics)
{
graphics.setGlobalAlpha(0);
setBackground(BackgroundFactory.createSolidTransparentBackgroun
graphics.setGlobalAlpha(255);
super.setBorder(BorderFactory.createSimpleBorder(new XYEdges(0,0,0,0)));
if(_inFocus)
{ graphics.drawBitmap(15,0,getWidth(),getHeight(),Bi
}
else
{
graphics.drawBitmap(15,0,getWidth(),getHeight(),Bi
}
}
protected void drawFocus(Graphics g, boolean on)
{
}
protected boolean navigationClick(int status, int time)
{
fieldChangeNotify(0);
return false;
}
};
bf.setChangeListener(new FieldChangeListener()
{
public void fieldChanged(Field field,int context)
{
// ((ButtonField)field).setEnabled(false);
}
});
add(bf);
LabelField lf = new LabelField(label, DrawStyle.HCENTER | USE_ALL_WIDTH)
{ //------Start Of Label Field
protected void layout(int width, int height)
{
super.layout(Display.getWidth()-160, height);
setExtent(Display.getWidth()-160, height);
}
protected void paint(Graphics g)
{
synchronized (UiApplication.getEventLock()){
g.setGlobalAlpha(0);
setBackground(BackgroundFactory.createSolidTransparentBackgroun
g.setColor(0xA7A7A7);
g.setGlobalAlpha(255);
}
super.paint(g);
}
};
lf.setBorder(BorderFactory.createSimpleBorder(new XYEdges(0,1,0,1), new XYEdges(0,0xA7A7A7,0,0xA7A7A7), Border.STYLE_SOLID));
lf.setFont(Font.getDefault().derive(Font.PLAIN, Font.getDefault().getHeight()-2));
if(lf.getFont().getAdvance(label)>Display.getWidth
{
lf.setPadding((50-lf.getPreferredHeight()*2)/2,0,0
}
else
{
lf.setPadding((50-lf.getPreferredHeight())/2,0,0,0
}
add(lf);
} //-----End Of Label Field
protected void sublayout(int maxWidth, int maxHeight)
{
super.sublayout( Display.getWidth(), 50);
setExtent( Display.getWidth(), 50);
}
public void paintBackground(Graphics graphics)
{
graphics.setBackgroundColor(0x353535);
graphics.clear();
graphics.drawBitmap(Display.getWidth()-Bitmap.getB
super.paintBackground(graphics);
}
}
02-20-2013 09:29 AM