01-09-2009 12:24 AM
I have a problem.
In custom field that extends EditField, I want to draw in the text and the image and to draw to an appropriate position in the cursor. Then, it was thought that it only had to calculate the advance of the font and the width of the image in the paint method, to display the text and the image, and to make focus similar, and tried.However, drawing of the cursor doesn't go well. When the cursor moves from the right to the left, a part of the cursor at the position immediately before remains.
Is there a good solution?
JDE Component Package : 4.6.0
Solved! Go to Solution.
01-12-2009 03:16 PM
To "remove" the cursor, you could draw it in its previous location using the background colour for your field. This could "erase" the cursor before you draw text in its previous location.
Or you could call the clear method on the Graphics object to clear everything. However, this means you have to redraw the entire field.
01-13-2009 02:00 AM
Thank you for the reply, Mark.
I had the Graphics.clear() method processed first in the paint() method. However, a part of the cursor remained as it was. Then, the another way was tested. It is to call the invalidate() method in the drawFocus() method at the end. It seems to go well in this method. However, the paint() method and the drawFocus() method are called when almost permanent.
Will this be a correct solution? Moreover, why does not the Graphics.clear() method clear the drawing area?
01-16-2009 11:59 AM
This could relate to the size of the graphics object you are working with. A field can invalidate part of itself, meaning only that section is redrawn. Anything outside of this region would be left alone and not cleared by a call to Graphics.clear.
02-04-2009 03:32 AM
I solved by myself.
"FocusChangeListener" is mounted with EditField. And, "invalidate()" was called in the "focusChanged()" method.
This became a great result for me.