GUI button not visible

projucer
gui

#1

Hello. I’ve created my first application. I’ve used Projucer -> New Project -> GUI application
And wrote following code, but my buttons are not visible.

MainContentComponent::MainContentComponent()
    : myButton("My Button")
{
    setSize (500, 500);
}

in MainContentComponent::~MainContentComponent()

if(! myButton.isDown()) myButton.setEnabled(false);
addAndMakeVisible(myButton);

in MainContentComponent::resized()

myButton.setBounds(margin, getHeight() /2 , getWidth() + 35, 35);
// also tried BoundsRelative

MainContentComponent::paint is empty

What am i missing?


#2

I’m not sure you understand what a destructir is. Ie. None of the things you are doing in ~MainContentComponent will have any effect on making your button visible, because that function is executed when the MaonContentComponent is destroyd.


#3

As well, the button you reference in resize is not myButton


#4

oh yeah i forgot to change button name, but still same


#5

The code does not belong in the destructor


#6

Did you see the GUI tutorials? Maybe it will help you to follow them and then modify them.
Just a quick thought: Are you sure that the coordinates you pass to myButton.setBounds are inside the MainContentComponents bounds? getHeight()/2 should work, but what’s the value of margin?