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: 41
Registered: ‎09-26-2008
My Device: Not Specified
Accepted Solution

Screen Refresh after Focus changed

I'm trying to color the complete background of a manager when one of its leaf fealds receives the focus. I'm programming against the version 4.3.

 

For this I've overridden the paint method to do this (the prefix m_ denotes a member variable of the object):

 

 

public void paint(Graphics graphics) { Field focussed = getLeafFieldWithFocus(); if ((focussed != null && m_RootHighlighter) || m_Highlight) { graphics.setBackgroundColor(Color.CYAN); if (m_RootHighlighter) { for (int i = 0; i < getFieldCount(); i++) { Field curField = getField(i); if (curField instanceof SubHighlighter) { ((SubHighlighter)curField).triggerHighlight(); } } } else if (m_Highlight) { m_Highlight = false; } } else { graphics.setBackgroundColor(m_BackgroundColor); } graphics.setColor(m_ForegroundColor); graphics.clear(); super.paint(graphics); }

 

One manager on the Manager stack (the one whose background should change color) is told that he's the root highlighter and calls the "triggerHighlight" method on all its child managers, which is implemented as follows:

 

 

public void triggerHighlight() { m_Highlight = true; for (int i = 0; i < getFieldCount(); i++) { Field curField = getField(i); if (curField instanceof SubHighlighter) { ((SubHighlighter)curField).triggerHighlight(); } } }

 

Each root highlighter has exact one leaf child (distanced from him by a few other manager layers) that can receive focus. 

 

 I now have a strange behavior: When I push a screen filled with Root Highlighter managers on the screen stack, the first manager, whose focusable leaf child gets focussed automatically, changes his background. When I scroll down, the next manager does not change background, although I see in debug mode that the focus wanders to its focusable field. When I've reached a manager not completely on the screen, which triggers a scrolling of the overlying manager, the color change takes place again.

 

I thought this might be a screen refreshing problem, so I added the following method to my custom manager class: 

 

 

protected void onFocus(int arg0) { super.onFocus(arg0); getScreen().doPaint(); }

 

 Now a kind of artifact of the background color change shows up (a small speck of the desired color, which doesn't go away when the focus leaves the manager) until I reach a part of the screen where the screen scrolls, at which point everything behaves as it should.

 

 Can somebody tell me whan makes a nonscrolling focus change different from a scrolling focus change and what I can do to fix this? Thank you.

 

 

 

BlackBerry Development Advisor
Posts: 15,753
Registered: ‎07-09-2008
My Device: BlackBerry PRIV
My Carrier: Bell

Re: Screen Refresh after Focus changed

You should call the Screen.invalidate method instead of Screen.doPaint.
Mark Sohm
BlackBerry Development Advisor

Please refrain from posting new questions in solved threads.
Problem solved? Click the Accept As Solution button.
Found a bug? Report it using Issue Tracker
Developer
Posts: 1,415
Registered: ‎07-30-2008
My Device: Not Specified

Re: Screen Refresh after Focus changed

I'm not sure if this is your problem but compiled under 4.0.2 running on 4.1(+/-) I had a button repaint

problem on scroll. I realized that it repainted properly and this almost fixes it ( or makes problem almost unnoticeable),

 

protected int moveFocus(int amnt,int status, int time)
{
int fux= super.moveFocus(amnt,status,time); 
invalidate();
return fux;
}

Developer
Posts: 41
Registered: ‎09-26-2008
My Device: Not Specified

Re: Screen Refresh after Focus changed

Excellent, that worked! Can you tell me the reason though, in context with the GUI framework?
BlackBerry Development Advisor
Posts: 15,753
Registered: ‎07-09-2008
My Device: BlackBerry PRIV
My Carrier: Bell

Re: Screen Refresh after Focus changed

The doPaint method is called by the system and should not be called directly.  The invalidate method instructs the BlackBerry device to redraw the specified screen, manager or field.
Mark Sohm
BlackBerry Development Advisor

Please refrain from posting new questions in solved threads.
Problem solved? Click the Accept As Solution button.
Found a bug? Report it using Issue Tracker
Highlighted
Contributor
Posts: 26
Registered: ‎01-18-2011
My Device: Not Specified

Re: Screen Refresh after Focus changed

Hello Mr Sohm ,

    In My application there is one horizontal field manager with four button field after that i have one vertical field manager with list field i have to change list field content according to upper button selected.i m trying to change replace list field with new list field  but it is not at all working  give me any suggestion.