Article View: borland.public.jbuilder.java.swing
Article #9499Re: Right way to use setText() with loop statement ?
From: John P. McGrath
Date: Wed, 29 Mar 2000 00:00
Date: Wed, 29 Mar 2000 00:00
32 lines
1695 bytes
1695 bytes
On Wed, 29 Mar 2000 15:17:28 -0800, mus wrote:
> Hiii .. I trying to modify Label.text using loop statement.
> Here is my code :
>
> for (int i=0;i <100;i++) {
> jLabel1.setText(Integer.toString(i));
> repaint();
> }
>
> the problem is only 99 is displayed in jLabel1. While other value not
> display at all. (I want to display value 1..10..99 sequentially).
I presume that you did not start another thread to run this code, and if
so, that is your problem. The repaint() method does not actually paint
the label, rather it schedules it to be repainted. The actual paint
operation is done on the AWT event thread.
Your code is (I presume) running on the event thread, so the paint() will
not occur until your code is complete, and returns control to the event
dispatcher. You would have to run your code in a separate thread to
ensure that this actually gets painted.
You would also have to do something to slow things down. Even in a
separate thread, your code would probably run to completion before the
paint code got a change to run. If you added a sleep() before each label
update, it should work.
--
John P. McGrath
<JPMcGrath@fast.net>
<jpm@nscs.fast.net>
Technical Details
Message-ID:
<MPG.134b95a74cfc92e798983e@forums.borland.com>Path:
arc1-ca.pugleaf.net!unknown!not-for-mailReferences:
<8bsa5e$gp2@bornews.borland.com>Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 111d45,ed1261101a8cb763 X-Google-Attributes: gid111d45,public From: John P. McGrath <JPMcGrath@fast.net> Subject: Re: Right way to use setText() with loop statement ? Date: 2000/03/29 Message-ID: <MPG.134b95a74cfc92e798983e@forums.borland.com> X-Deja-AN: 603788357 References: <8bsa5e$gp2@bornews.borland.com> Organization: Another Netscape Collabra Server User Newsgroups: borland.public.jbuilder.java.swing