getComponentAt()


#1

The following method will dynamically add a slider to my main window with a right mouse-click. I then want to use a left mouse click to see which slider is being clicked on. It does return the name of my main component but never that of my slider. Am I approaching the task in the wrong way? Can anyone advise?

[code]void PanelEdit::mouseDown(const MouseEvent &e)
{
PopupMenu m;
m.addItem(1, “Insert Slider”);
m.addItem(2, “Lock”);

if (e.mods.isRightButtonDown())
{
const int result = m.show();
if (result == 1)
{
Slider* sld = new Slider(“slider”);
sld->setBounds(e.getMouseDownPosition().getX(), e.getMouseDownPosition().getY(), 300, 50);
sld->setInterceptsMouseClicks(false, false);
addAndMakeVisible(sld);
sliders.add(sld);
}
}
else{
Component* c = getComponentAt(e.getMouseDownPosition());
Logger::writeToLog(c->getName());
}
}[/code]


#2

Sounds like the Slider is intercepting mouse events as it should. These don’t get passed to the parent Component. You could put an invisible Component over the top of everything and then pass the events to the other components underneath. But this suggests you might be going about things the wrong way. Some kind of Listener/Broadcaster system would be better.