Modified the paint callback to avoid flicker in the on-screen keyboard