Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / First Aid / April 2004

Tip: Looking for answers? Try searching our database.

Problems with JLabel

Thread view: 
Zalek Bloom - 06 Apr 2004 03:18 GMT
On my applet I defined a JLabel to display messages. I see the label, but after
I changed it with:

Lbl1.setText("this is a warning");

I don't see a change - I see the old contends.

My question: can we use JLabel to display messages that applet is changing? If
the answer is yes - how we can do it?

Thanks,

Zalek
Stephan Wehner - 06 Apr 2004 18:35 GMT
What little information you offer about your problem, it should work that way.
Are you sure your Lbl1.setText("...") is executed? What's the code?

Stephan
_____________________________
Stephan Wehner
Editor, Traffic Life: Passionate Tales and Exit Strategies
www.trafficlife.com

> On my applet I defined a JLabel to display messages. I see the label, but after
> I changed it with:
[quoted text clipped - 9 lines]
>
> Zalek
Zalek Bloom - 08 Apr 2004 02:17 GMT
> What little information you offer about your problem, it should work that way.
> Are you sure your Lbl1.setText("...") is executed? What's the code?
>
> Stephan

Stephan

I fixed this problem, but I have no explanation what happened.

I defined an applet and in the applet I defined JLabel. I defined a
separate class as a Listener. The Listener extended my applet - so my
definition of JLabel and a TextField were in applet only. I had no
problem to change TextFiled - but JLabel was never changed. I put
System.out.println after label.setText - so I am sure the line was
executed.

Than I decided to define the Listener not as a separate class, but in
the applets: label1. addActionListener(this); and move the method
actionPerformed() to the applet - now everything is working OK.
Why? No idea.

Zalek

> > On my applet I defined a JLabel to display messages. I see the label, but after
> > I changed it with:
[quoted text clipped - 9 lines]
> >
> > Zalek
Tom - 06 Apr 2004 20:22 GMT
> On my applet I defined a JLabel to display messages. I see the label, but after
> I changed it with:
[quoted text clipped - 9 lines]
>
> Zalek

I seem to have more problems with this in applets than in
applications.  You need to force the JLabel to repaint.  Sadly, just
calling the repaint() probably won't work (since it is probably
already called by the setText(String) method.

A kludge that I have used is to change the visibility.  Make the
JLabel invisible and then visible again.  For some reason that seems
to trigger the repainting faster than just a call to repaint.
Alex Hunsley - 14 Apr 2004 12:18 GMT
>>On my applet I defined a JLabel to display messages. I see the label, but after
>>I changed it with:
[quoted text clipped - 18 lines]
> JLabel invisible and then visible again.  For some reason that seems
> to trigger the repainting faster than just a call to repaint.

Are you calling setText from the event despatch thread? These problems could be
a result if you're not doing that.
Any method calls that affect realized components should be called from the EDT!
Java won't complain explicitly if you don't do this, but things may not work
all the same.

alex
Roedy Green - 16 Apr 2004 00:08 GMT
>Are you calling setText from the event despatch thread? These problems could be
>a result if you're not doing that.
See http://mindprod.com/jgloss/swing.html
and read up on invokeLater for how to set a component from something
other than the Swing thread.

The other common problem is you are tying up the Swing thread in some
event handler, so it can't get around to doing the repaint.

--
Canadian Mind Products, Roedy Green.
Coaching, problem solving, economical contract programming.
See http://mindprod.com/jgloss/jgloss.html for The Java Glossary.


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.