• Post Reply Bookmark Topic Watch Topic
  • New Topic

Updating Components  RSS feed

 
Anonymous
Ranch Hand
Posts: 18944
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am making my first "Top to Bottom" application, (an applet) which computes all of the prime numbers between two starting values. I am displaying the results in a JTextArea. I am also attempting to provide error messages and updates in the same area. I do a:
theText.setText("Computing the primes ...");
just before I do the computations and the messate does not show up. I have tried adding:
repaint();
after it but this message is skipped. I did an:
Graphics screen
...
theText.update(screen)
and while this got the message to display it also generated a NullEventException.
While I could trap the exception, that is not very clean. I am NOT currently using threads. Is this my problem?? Does Java not have enough time to update the display before my other computations have completed and they get displayed?
 
paul wheaton
Trailboss
Posts: 22537
Firefox Browser IntelliJ IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
First, you say something about how this is an applet and an application. Usually these are two different animals. I suggest that you stick to application and introduce the applet factor later.
I think to see the message you will have to implement a thread. Java will do the actual painting while waiting for events - but you aren't waiting for events yet, you are working on the computations.

 
Anonymous
Ranch Hand
Posts: 18944
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
My apologies, I am still getting familiar with Java terminology. My old school education terms everything an application.
This is an applet. It works great, except this one text message does not display. I have considered introducing threads by since what I am doing is very linear, I didn't see the need.
 
paul wheaton
Trailboss
Posts: 22537
Firefox Browser IntelliJ IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It's been a while since I had to do this - before Swing, I made a progress bar. In order for the progress bar to show anything, I remember I had to put it in its own thread. I wish I could remember more details for you.

 
Rick Lowe
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Try paintImmeditly() on the component after
setting the component.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!