Solved

Implement Blinking Caret

Posted on 2007-03-18
2
697 Views
Last Modified: 2013-12-22
I'm implementing an editor component from scratch (for J2ME environment)
Now I'm totally confused on how to make the caret blink efficiently
A separate thread is used to change the caret's blink-state at regular intervals
But how should I deal with drawing it ?
Should the thread, signal the component (extended from Canvas) to repaint (redrawing everything) ? that would be inefficient in my opinion
It neither can draw directly into the component's Graphics object, only the paint method is responsible for that
Could someone please help me ?
0
Comment
Question by:hoomanv
2 Comments
 
LVL 35

Accepted Solution

by:
TimYates earned 500 total points
ID: 18743135
If it turns out that it *is* inefficient (it may be fine to repaint the whole thing, even though as you say it's a bit of a waste of processing), then you could look at managing a "dirty rectangle list" ie, you keep a list of rectangles which need repainting, and only repaint the parts of the screen that are within each rectangle when it comes to redraw...

You will have to handle the case when the whole canvas needs to be redrawn...

Personally, I would see how slow the full repaint is first of all...  as it is the easiest fix...

Maybe, only flicker the cursor once the user has been idle for a fixed time?  That way it is only doing these full repaints once a second or so when the user isn't doing anything else?

Tim
0
 
LVL 30

Expert Comment

by:Mayank S
ID: 18744560
BTW all UI modifications should be done from the EDT so try not to implement another thread to do it/ repaint.
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

For beginner Java programmers or at least those new to the Eclipse IDE, the following tutorial will show some (four) ways in which you can import your Java projects to your Eclipse workbench. Introduction While learning Java can be done with…
Are you developing a Java application and want to create Excel Spreadsheets? You have come to the right place, this article will describe how you can create Excel Spreadsheets from a Java Application. For the purposes of this article, I will be u…
This tutorial covers a step-by-step guide to install VisualVM launcher in eclipse.
This tutorial explains how to use the VisualVM tool for the Java platform application. This video goes into detail on the Threads, Sampler, and Profiler tabs.

895 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now