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: 418
Registered: ‎06-22-2010
My Device: na
My Carrier: blackberry developer

Re: how to repaint a text in a labelfield

paintBackground(g); isnt clearing my old text

Developer
Posts: 418
Registered: ‎06-22-2010
My Device: na
My Carrier: blackberry developer

Re: how to repaint a text in a labelfield

protected void paint(Graphics g) {
int oldColour = g.getColor();
try {
g.setColor(g.isDrawingStyleSet(Graphics.DRAWSTYLE_FOCUS) ? _foregroundColorFocus
: _foregroundColor);

text = mPropertyItem.getAttribute("text");
if (text.indexOf("$") != -1) {
text = StringUtil.expandUrl(
mPropertyItem.getAttribute("text"),
mPropertyItem, mDataItem);
}

if(alignment.equalsIgnoreCase("center")||alignment.equalsIgnoreCase("centervertical")){
g.drawText(text, (getPreferredWidth() / 2)
- (getFont().getAdvance(text) / 2),
(getPreferredHeight() / 2)
- getFont().getHeight() / 2);
}
if(alignment.equalsIgnoreCase("right")){
g.drawText(text, (getPreferredWidth() / 2)
+ (getFont().getAdvance(text) / 2),
1);
}
if(alignment.equalsIgnoreCase("right|center")){
g.drawText(text, (getPreferredWidth() / 2)
+ (getFont().getAdvance(text) / 2),
(getPreferredHeight() / 2)
- getFont().getHeight() / 2);
}
if(alignment.equalsIgnoreCase("left")){
g.drawText(text,1,
1);
}
if(alignment.equalsIgnoreCase("left|center")){
g.drawText(text,1,
(getPreferredHeight() / 2)
- getFont().getHeight() / 2);
}
if(alignment.equalsIgnoreCase("top")){
g.drawText(text,1,
1);
}
if(alignment.equalsIgnoreCase("top|center")){
g.drawText(text,(getPreferredWidth() / 2)
- (getFont().getAdvance(text) / 2),
1);
}
if(alignment.equalsIgnoreCase("bottom")){
g.drawText(text,1,
getFont().getHeight());
}
if(alignment.equalsIgnoreCase("bottom|center")){
g.drawText(text,(getPreferredWidth() / 2)
- (getFont().getAdvance(text) / 2),
getFont().getHeight());
}
if(alignment.length()==0) {
g.drawText(text,0,0);
}
if(reload==false){
//g.clear();

g.setColor(g.isDrawingStyleSet(Graphics.DRAWSTYLE_FOCUS) ? _foregroundColorFocus
: _foregroundColor);
g.drawText("Success",0,0);

}
//lbf.setText(text);

super.paintBackground(g);

} finally {
g.setColor(oldColour);
}
}
};

 

above is my code of labelfield paint......reload==false is a boolean which i am setting when i get new text value and click another bitmapfield to change the text

Developer
Posts: 418
Registered: ‎06-22-2010
My Device: na
My Carrier: blackberry developer

Re: how to repaint a text in a labelfield

i think i need to do something other than what i am doing in this block

 

if(reload==false){
g.clear()
g.setColor(g.isDrawingStyleSet(Graphics.DRAWSTYLE_FOCUS) ? _foregroundColorFocus
: _foregroundColor);
g.drawText("Success",0,0);

}

Developer
Posts: 19,633
Registered: ‎07-14-2008
My Device: Not Specified

Re: how to repaint a text in a labelfield

you need to setBackgroundColor(...) before your clear()