JUCE HBox or VBox?


How are you meant to align components (such as buttons, labels, text boxes)?


Are these java concepts?

Override Component::resized(), call your child components’ setBounds(x, y, width, height).

You can make arrays of them, and place them accordingly with a bit of math…


You can also, as I recently discovered, give Components ID's which can then be used to align them with a string expression e.g.



compC.setBounds("CompA.right, 0, parent.width, CompB.top");

See https://www.juce.com/api/classComponent.html#a821833808f451753df397802d9d6160a


I'd probably recommend against this method nowadays.. It works, but from experience we've generally found that the most debuggable and readable way to lay them out is using Rectangle methods (grep the codebase for "removeFromTop", "removeFromLeft" etc and you'll find many examples of this)

(A new layout system that uses a more "flexbox" style paradigm is on our to-do list though!)