aspose file tools*
The moose likes Swing / AWT / SWT and the fly likes Repainting jPanel in Applet Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "Repainting jPanel in Applet" Watch "Repainting jPanel in Applet" New topic
Author

Repainting jPanel in Applet

Jesse Miller
Ranch Hand

Joined: Apr 05, 2010
Posts: 37
I have a jApplet that contacts a web service every minute to update the content that it displays on a jPanel. When I run the applet in my NetBeans IDE it works fine, I have a countdown timer that shows when the panel will be updated and it updates at the correct time. But when I publish this applet as a Web Start or embed it as an applet, the repainting does not work. The countdown timer still works but the content of the jPanel is never updated. What is going on? Thanks

Ernest Friedman-Hill
author and iconoclast
Marshal

Joined: Jul 08, 2003
Posts: 24187
    
  34

Are you sure that the applet version manages to get the updated data? Applets have restrictions on the kind of network connections they can create; in general, an unsigned applet can only talk to the server it was downloaded from.


[Jess in Action][AskingGoodQuestions]
Jesse Miller
Ranch Hand

Joined: Apr 05, 2010
Posts: 37
Well, it connects to the service initially to get data and populate the jPanel. But it never connects again, so it never updates the jPanel. I would think that if it was able to connect the first time then being able to connect to the web service would not be the problem. I was thinking that is was some problem with actually repainting the jPanel. Do you think differently?
Ernest Friedman-Hill
author and iconoclast
Marshal

Joined: Jul 08, 2003
Posts: 24187
    
  34

Sounds like my first guess was wrong. Are you looking at the "Java Console" to see if you're getting any stack traces?
Jesse Miller
Ranch Hand

Joined: Apr 05, 2010
Posts: 37
Yea, Ive been watching the Console. I put in several system.out.println to follow the execution of everything and the Java Console from the Applet is the same as that from my NetBeans IDE. And there are no error messages. Its just not repainting as far as I can tell...
Ernest Friedman-Hill
author and iconoclast
Marshal

Joined: Jul 08, 2003
Posts: 24187
    
  34

Hmmm. Weirdness. Well, how is the repainting supposed to be happening? Do you have a Swing "tree model", and is it being updated in such a way that it fires change events to the view?
Jesse Miller
Ranch Hand

Joined: Apr 05, 2010
Posts: 37
The timer counts down and when it reaches 0 it prompts a panel.repaint(). The panel has many rectangles on it that are filled with different colors. The server call updates an array that tells the jpanel what color to paint each component. Do you want the code?
Jesse Miller
Ranch Hand

Joined: Apr 05, 2010
Posts: 37
Also, when I refresh the page the data stays the same. If I launch the applet again in a new tab then the data is correct but never updates after the initial load, same as before. This is really puzzling..I can see everything working in the background but nothing gets updated on the screen.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Repainting jPanel in Applet