Repaint method is skipped when having multiple objects of the same class


#1

Hi all,
I have a class which is inherited from the Slider class. I instantiated this class twice, and the two objects are close to each other on the UI (not overlapping). I need to call repaint() on mouse exit. So I overrode the mouseExit function and simply called repaint() inside it. I also added some DEBUG lines in the mouseExit and paint methods to see what happens.
The problem is, sometimes when I move mouse from one component to the other one the paint() method of the first component is not called. Assume the sliders are called SLIDER1 and SLIDER2 and I move the mouse from SLIDER1 to SLIDER2. This is how the DEBUG messages look like:

MOUSE EXIT SLIDER1
PAINT SLIDER2
```

I expect it to look like this:

MOUSE EXIT SLIDER1
PAINT SLIDER1
PAINT SLIDER2

As I said it happens from time to time. Sometime it just works fine and sometimes it ignores the first paint method.

#2

Maybe it just didn’t need to repaint the first one… If it did a repaint recently and then the mouse exits, there’s no reason to expect that it would invoke a repaint again. What makes you think this behaviour is in some way wrong?


#3

Do you mean calling repaint() does not force repainting the object? But sometimes with the same mouse movements it repaints the first one. It is a little bit weird for me, why the exact same mouse movements causes two different results.
The problem is, when it does not call repaint, the first object just disappears from the UI and will appear again if I hover the mouse over it.


#4

No, I meant that repaint might not be called because it didn’t need to be called. But if it’s disappearing then maybe it’s something you’re overriding in your subclass that’s messing up the parent class’s behaviour?


#5

Thanks for taking time and replying to this.
Unfortunately I cannot post my code here so we can go deeper into details, but as far as I can see there is no weird behaviour in the subclass. I am calling the repaint() function explicitly in the mouseExit function. And in the first line of paint() function I added a DBG line to see if the program logic reaches there. But it sometimes does not hit that line (ignores the repaint() function call).

void MyClass::paint(Graphics& g)
{
DBG("In Paint: " + dspParam->getName() );

… rest of the code
}

void MyClass::mouseExit(const MouseEvent& e)
{
repaint();
}