Problem with addAndMakeVisible and resized

I have a custom component.

If I write this:

[code]
int cellWidth = 100;
int cellHeight = cellWidth * (3 / 4);

target = new DragAndDropDemoTarget();
target->setBounds (FIRST_CELL_X,FIRST_CELL_Y, cellWidth, cellHeight);
addAndMakeVisible (target);[/code]

I can’t see the component in the GUI.

Instead, doing this:

[code]int cellWidth = 100;
int cellHeight = cellWidth * (3 / 4);

target = new DragAndDropDemoTarget();
addAndMakeVisible (target);[/code]

and putting this , in the rezized method of the main GUI Component:

[code]void DemoEditorComponent::resized()
{
resizer->setBounds (getWidth() - 16, getHeight() - 16, 16, 16);
target->setBounds (getWidth() - 260, getHeight() - 160, 250, 150);

}[/code]

the component is shown.

Do you know why?

thanx

hmmm

I ONLY ever put setBounds in resized. So comps are always added THEN get bounds set.

Perhaps it’s required to do it in this order?

doh!

:lol: :lol:

:shock: :shock: :shock:

not sure i get it either… unless it’s about using * 0.75f instead of (3/4)…

personally i always put my setBounds in the resized() call too. not sure if it makes a difference, but i always set my bounds AFTER the component has been added and made visible. makes more sense to me logically, not sure if it actually has an effect.

integer division 4 into 3 gives 0.

yeah that’d do it :hihi: wanna make sure that multiplier isn’t just being done as an int calculation before the result gets converted to an int. your second ‘working’ code example doesn’t even use the *(3/4) result as it has getWidth/constant style values. so i’d put *0.75f in instead and see how that fares.

See, I told you to check the bounds variables to make sure they aren’t zero or anything, you never showed me that (3/4) line. :roll:

:smiley: :smiley: :smiley:
Maybe It’s better if I play my guitar than coding!
It’s very hot here,my head hurts :stuck_out_tongue: