General issues


I have some issues (questions in some cases) with my application:

  1. I managed to remove the title bar and the borders around the main window. Now, I need to move somehow the window. I started by this code on the main component of the window:

     void mouseDrag(const MouseEvent& event) override {
     int x = event.getScreenPosition().x - event.getPosition().x;
     int y = event.getScreenPosition().y - event.getPosition().y;
         setBounds(x, y, getWidth(), getHeight());

and indeed I can move the window but 1) it works the second time I click and drag and 2) It turns my window grey with no content inside it.

  1. In addition to 1) I need to have 3 buttons minimize, maximize and close but I only know the code for the close button: JUCEApplication::getInstance()->systemRequestedQuit(); or JUCEApplication::getInstance()->quit();. What’s the code for minimize, maximize/restore ?

  2. I have a lot of nested custom components in my application. Is there any way for a child component to access parent component’s function? Notice that by parent component’s function I mean the ones I write when I create the class that inherits from component class and not just the functions from the base Component class. I don’t if that makes sense but it’s hard to move info “around” and I don’t like to use global variables.

Thanks in advance for your time and help.


Question 2: in ResizableWindow: ResizableWindoe::setMinimised (bool shouldMinimise) ff.

Question 3: You get the parent component using Component::getParentComponent()

if (Component* parent = getParentComponent()) {
    // do something 

If you think your parent is a special thing you can use this together with dynamic_cast, e.g.:

if (GroupComponent* group = dynamic_cast<GroupComponent*> (getParentComponent())) {
    group->setText ("New title set from my child");

No. 1 I don’t know, but maybe tell what kind of window this is, because there are different subclasses of Component, that can be put on the desktop… That might ring a bell for somebody…


Q1 :
in you main app window constructor :
someComponent.addMouseListener (this, true);

in the members:

ComponentDragger dragger;

void mouseDrag (const MouseEvent& e) override
    dragger.dragComponent (this, e, nullptr);


Yeah it works now. However when I start moving the mouse goes automatically to top-left corner. Any way to keep the cursor where I clicked?


For this, you could also use findParentComponentOfClass() of Component, like this:

GroupComponent* group = this->findParentComponentOfClass <GroupComponent> ();

Which I find more readable because it makes clear what I am trying to do (but yes, it still uses the same approach with dynamic_cast internally)