• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • Devaka Cooray
  • Ron McLeod
  • Jeanne Boyarsky
Sheriffs:
  • Liutauras Vilda
  • paul wheaton
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Piet Souris
  • Carey Brown
  • Tim Holloway
Bartenders:
  • Martijn Verburg
  • Frits Walraven
  • Himai Minh

Repainting within a applet

 
Ranch Hand
Posts: 101
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I have the following problem:
I would like to repaint only certain object(s) within a applet based on a certain trigger. How can I accomplish this without refreshing the while applet?
 
Bartender
Posts: 4121
IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The simple answer is just to call repaint() on the sub-component of the applet. ( For example, if you have a Canvas called imageCanvas1 that you want to repaint without repainting the entire applet, you could call it's repaint() method directly by calling :

)
However, this solution is not as simple as it seems... if you do anything that would cause the sub-component to change size, or change location on the screen, you will need to call doLayout() on the component that holds your sub-component... and doLayout() forces a repaint() to be called on the component that doLayout() is called on, and on all the sub-components of that component.
So the answer is, for small changes, simply calling repaint() on a sub-component will work, but for most things you cannot get away with not doing a repaint of the top level GUI element. I'm sure that if this is a big problem for you, you can find some way around it, like creating a Panel big enough to hold the maximum size of all your sub-components and then calling doLayout() on that Panel instead of the applet... but I am not sure if that is any better because all your sub-components get painted anyway...
Anyway, here's some code that I used to test this out... all you need to do to see what is going on is to replace the two images I was using ( washu and abbey ) with images of your own, and then comment and uncomment lines to see what goes on...

Enjoy!
HTH,
-Nate
 
Sometimes you feel like a nut. Sometimes you feel like a tiny ad.
the value of filler advertising in 2021
https://coderanch.com/t/730886/filler-advertising
reply
    Bookmark Topic Watch Topic
  • New Topic