ComboBox Mac trouble


#1

The choice of the item does not work normally. It works only after numerous pressing.

A captuture problem on video:

It appears only on Mac. On Win is ok.

ParamEqAudioProcessorEditor::ParamEqAudioProcessorEditor(ParamEqAudioProcessor& p) : AudioProcessorEditor(&p), processor(p) { setSize(650, 500);
TypeBox = new ComboBox("CBox");
TypeBox->setBounds(60 + 70, 70, 100, 40);
addAndMakeVisible(TypeBox);
//can be uncommented without effect
//TypeBox->addListener(this);
TypeBox->addItem("HP", 1);
TypeBox->addItem("LP", 5);

}

void ParamEqAudioProcessorEditor::paint (Graphics& g)
{
g.fillAll(Colours::blue);
g.setFont(Font(24));
g.setColour(Colours::white);
}


#2

Tried this in Ableton and Logic Pro X and seems to work fine for me. Must be something else that you are doing wrong. Also you should not set the bounds in your constructor but in your resize method. Also make sure that you initialise TypeBox before calling setSize (650, 500);.


#3

Why? I always assumed that setting the bounds of a child in the constructor of the parent was perfectly fine as long as they don’t change upon resizing the parent (and it always worked as expected).

Also why? Nothing in the bounds of the ComboBox depends upon the items that it shows… or did I misinterpret your statement?


#4

Yes, you are right. If your editor never resizes then you can call setBounds in the constructor. In any case, it’s more future-proof to do this in the resized() method.

If you ever do move the TypeBox->setBounds to the resized method, then you would get a crash as setSize (650, 500) calls resized internally. If TypeBox hasn’t been initialised yet then you will be dereferencing an uninitialised pointer.


#5

Ah, my bad, I interpreted it as “be sure to initialize (= add your items to) the combobox before calling (its) setSize() method”, which is not what you meant.
I see it now, totally agree with you, I tend to set the size of parent components at the very end of their constructors.