Java: repaint() Waking Nightmare
You know those times, while coding, when it feels like you’ve drifted into a horrible nightmare where nothing you do works?
This happened to me today.
I wanted the little app I’m making to display a green tick or a red cross depending on whether the user had entered valid credentials. Simple? Yeah. Everything went really well, I extended a JPanel to handle the tick/cross display area (tickCross), got the POST code going, strung together the rest of the GUI elements.
The problem was that tickCross.repaint() wasn’t reliably repainting. about 30% of the time the image wouldn’t be painted. The method was being called, but nothing was happening. I tried Google, re-read the related Sun Java docs and was reminded that: “repaint() does not actually paint. It calls the peer repaint which enqueues a request in some platform-dependent way inside the native GUI for a repaint.” – MindProd. Great. My OS was deciding when I was allowed to draw.
Somewhat more irritated, I then had to resort to every programmer’s backup tool: trial and error.
Thanks Rob (we make websites), for laughing at this post and emailing me the following:
tickCross.repaint(); tickCross.setVisible(false); tickCross.setVisible(true);
?! How about:
Invalidate();
I swear I tried that, honest!
After much frustration, I struck a solution. It’s not elegant, I’d even say it’s hacksih, but it works.
1 2 3 | tickCross.repaint(); tickCross.setVisible(false); tickCross.setVisible(true); |
Cross or tick when I damn well want them, every time.
Like this post? Move it on along with:
Email |
delicious |
Digg |
Tweet |
Reddit |
Newsvine |
Furl |
Google |
Stumble |
HaoHao
| Trackback: |
Scroll to post title



























Recent Comments
Installing Jdownloader In Ubuntu
thanks works as it should....
Mon, 15 Feb 2010 15:40:22 +0000
Tag Cloud
LinkedIn
Tue, 09 Feb 2010 07:55:50 +0000
Great Wall
LinkedIn
Tue, 09 Feb 2010 07:55:41 +0000
Roys Wordpress Cumulus Tag Cloud In Rapidweaver
hi, congrats, very helpful guide!
my problem. i get this flash working with rapidweaver but if i click on one of these tags in the cloud I'm linked to a dead url. i guess it has something to do with the servers root path because there is an extra "html" part in the linking url. as my provider requires i have to put all stuff for the web into a subfolder called "html", so that it looks like ./html/webcontent..., so actually my domain is this html folder.
if you tske a quick look at this wrong link you'll see that if you delete the html part in the url you'll get the correct path. do you have an idea about this? thanks a lot
Mon, 08 Feb 2010 22:41:28 +0000
Js Kit Comments Correct Usage Of The Permalink And Path Attributes
HTML codes are always confusing but once one gets the hang of it, things will be pretty smooth from there on.
--
technology essays | essay topics
Wed, 03 Feb 2010 09:04:20 +0000
Js Kit Comments Correct Usage Of The Permalink And Path Attributes
不错啊 挺好的 希望大家有空去也去我的小站光临 http://www.8zyu.com/ welcome to http://www.8zyu.com/ for UGG Boots
Tue, 02 Feb 2010 03:12:37 +0000