I have an annoying problem. I have 3 GUI components on my plugin. There are placed side by side. There is no gap between them. The 4th GUI is between the second and third ones.
I am trying to create a kinda parameter changed indication by drawing a red dot on the 4th GUI component. I can get the parameter changed info from the plugin processor. So the only thing that should be done(i guess) is to trigger the paint or resized methods of the 4th component. Because I have a mechanism in the paint method that will draw an image on the 4th component. I tried to call repaint of the 4th component from first, second and third components, but it didn’t work. Also, I tried to call the paint function of the 4th component by inserting the “g” but it tries to draw the image within the component (within first, second and third one ) that calls the 4th component. How can I call the paint function of a component from another one and make it work properly? Is it possible to reach to paint and resized methods of a GUI from the audio processor directly? Please help me. I’m about to lose my mind
You cannot call paint from an other Component. It is called by the framework.
If you call paint yourself, the graphics context you are forwarding is not set up to draw in that position, and the clip region will make so you don’t see anything of your drawing.
Instead call repaint() of your Component 4 and the framework will call the paint() method of Component 4 with a properly set up graphics object.
repaint isn’t being called until i move the cursor over the component 4 or resize the window. When one of knobs in the other components has changed , i want to draw a red dot on the 4th component.But calling repaint method of 4 component doesn’t work.
BTW thank you very much for answering ormally all components, should be calling their paint method with a certain time interval, right? In my plug in the 4th component doesn’t call it till i move the mouse cursor over it or resize the window. Is there any setting that we can change this behavior?
Normally paint is called, when the OS or the framework deems it necessary. It has a way to figure out, if the content is still intact.
A repaint is triggered
- when visibility changed (minimised, created etc.)
- when something was dragged across (what you observed, could also be another window etc.)
- when it was resized or moved (e.g. setBounds was called)
- when manually marked as dirty (which is done by calling repaint())
N.B. those situations can cascade, e.g. a non opaque component will trigger a paint of it’s parent first, because it doesn’t know how to get the background
For a continuous paint, usually you have a Timer calling repaint() at a certain frequency.
Another approach is, if the information you want to display can send a changed message, e.g. using a ChangeBroadcaster.