# Unrelated components on top of each other

**URL:** <https://forum.juce.com/t/unrelated-components-on-top-of-each-other/7002>\
**Category:** General JUCE discussion\
**Created:** [June 9, 2011, 1:27pm UTC](https://forum.juce.com/t/unrelated-components-on-top-of-each-other/7002 "2011-06-09T13:27:03Z")\
**Posts on this page:** 12\
**Page:** 1

<div class="post-metadata">

**Author:** ![Tsury](https://avatars.discourse-cdn.com/v4/letter/t/71c47a/32.png) [@Tsury](https://forum.juce.com/u/Tsury)\
**Post date:** [June 9, 2011, 1:27pm UTC](https://forum.juce.com/t/unrelated-components-on-top-of-each-other/7002/1 "2011-06-09T13:27:03Z")

</div>

Hi.

I have two sibling components, each containing a ComboBox as a child.

The two sibling components are arranged in two rows, one above the other.

Supposed that the in the top components ComboBox contains enough items that when opened, it should be seen on top of the bottom components,

how can I achieve this functionality?

Currently, when opened, the ComboBox is clipped behind the bottom component…

Thanks!

---

<div class="post-metadata">

**Author:** ![jules](https://avatars.discourse-cdn.com/v4/letter/j/41988e/32.png) [@jules](https://forum.juce.com/u/jules)\
**Post date:** [June 9, 2011, 1:34pm UTC](https://forum.juce.com/t/unrelated-components-on-top-of-each-other/7002/2 "2011-06-09T13:34:47Z")

</div>

I don’t understand your question - when a combobox is opened, it always pops up in front of other windows…?

---

<div class="post-metadata">

**Author:** ![Tsury](https://avatars.discourse-cdn.com/v4/letter/t/71c47a/32.png) [@Tsury](https://forum.juce.com/u/Tsury)\
**Post date:** [June 9, 2011, 1:46pm UTC](https://forum.juce.com/t/unrelated-components-on-top-of-each-other/7002/3 "2011-06-09T13:46:42Z")

</div>

> [@jules](#):
>
> I don’t understand your question - when a combobox is opened, it always pops up in front of other windows…?

My code does what illustrated in the top of the image, I want to achieve the bottom functionality…

---

<div class="post-metadata">

**Author:** ![jules](https://avatars.discourse-cdn.com/v4/letter/j/41988e/32.png) [@jules](https://forum.juce.com/u/jules)\
**Post date:** [June 9, 2011, 1:50pm UTC](https://forum.juce.com/t/unrelated-components-on-top-of-each-other/7002/4 "2011-06-09T13:50:29Z")

</div>

The combobox opens a new floating window to show its listbox - just like any other pop-up menu. There’s no way you could get it to do what you’ve drawn there.

---

<div class="post-metadata">

**Author:** ![TheVinn](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/thevinn/32/806_2.png) [@TheVinn](https://forum.juce.com/u/TheVinn)\
**Post date:** [June 9, 2011, 2:00pm UTC](https://forum.juce.com/t/unrelated-components-on-top-of-each-other/7002/5 "2011-06-09T14:00:34Z")

</div>

Are you still using a ListBox to display the menu, instead of a PopupMenu?

---

<div class="post-metadata">

**Author:** ![Tsury](https://avatars.discourse-cdn.com/v4/letter/t/71c47a/32.png) [@Tsury](https://forum.juce.com/u/Tsury)\
**Post date:** [June 9, 2011, 2:08pm UTC](https://forum.juce.com/t/unrelated-components-on-top-of-each-other/7002/6 "2011-06-09T14:08:44Z")

</div>

> [@TheVinn](#):
>
> Are you still using a ListBox to display the menu, instead of a PopupMenu?

You caught me 🙂

I tried to alter the LookAndFeel (adding a virtual drawComboBox(…, Component&) as we discussed) but it was too much for me, I just started working with Juce…

The ListBox+Button works very nicely, the only problem left is what I describe here…

I would go for the solution we discussed earlier if I could work it all out…

---

<div class="post-metadata">

**Author:** ![TheVinn](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/thevinn/32/806_2.png) [@TheVinn](https://forum.juce.com/u/TheVinn)\
**Post date:** [June 9, 2011, 2:11pm UTC](https://forum.juce.com/t/unrelated-components-on-top-of-each-other/7002/7 "2011-06-09T14:11:11Z")

</div>

> [@Tsury](#):
>
> [quote=“TheVinn”]Are you still using a ListBox to display the menu, instead of a PopupMenu?

You caught me :)[/quote]

If you insist on using a ListBox instead of a PopupMenu, then put it in its own window (i.e. heavyweight Component) so it can float over everything. You can copy the code from PopupMenu.

---

<div class="post-metadata">

**Author:** ![TheVinn](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/thevinn/32/806_2.png) [@TheVinn](https://forum.juce.com/u/TheVinn)\
**Post date:** [June 9, 2011, 2:11pm UTC](https://forum.juce.com/t/unrelated-components-on-top-of-each-other/7002/8 "2011-06-09T14:11:54Z")

</div>

> [@Tsury](#):
>
> I would go for the solution we discussed earlier if I could work it all out…

I don’t see what was so complicated about patching juce\_ComboBox.cpp to build the menu using a virtual function…

---

<div class="post-metadata">

**Author:** ![jules](https://avatars.discourse-cdn.com/v4/letter/j/41988e/32.png) [@jules](https://forum.juce.com/u/jules)\
**Post date:** [June 9, 2011, 2:21pm UTC](https://forum.juce.com/t/unrelated-components-on-top-of-each-other/7002/9 "2011-06-09T14:21:55Z")

</div>

I just had a look at ComboBox, and adding a virtual method to create the menu would be a bit awkward because it’d also mean exposing the internal ItemInfo class, and the item list, etc… I’m not really keen to break the encapsulation there.

---

<div class="post-metadata">

**Author:** ![Tsury](https://avatars.discourse-cdn.com/v4/letter/t/71c47a/32.png) [@Tsury](https://forum.juce.com/u/Tsury)\
**Post date:** [June 9, 2011, 2:23pm UTC](https://forum.juce.com/t/unrelated-components-on-top-of-each-other/7002/10 "2011-06-09T14:23:58Z")

</div>

> [@TheVinn](#):
>
> [quote=“Tsury”]I would go for the solution we discussed earlier if I could work it all out…

I don’t see what was so complicated about patching juce\_ComboBox.cpp to build the menu using a virtual function…[/quote]

After I had added the drawCombo(Component&) and changed the drawCombo(ComboBox&) to use it, what do I do then?

Derive from LookAndFeel and set it as the LookAndFeel of a new control deriving from ComboBox?

---

<div class="post-metadata">

**Author:** ![TheVinn](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/thevinn/32/806_2.png) [@TheVinn](https://forum.juce.com/u/TheVinn)\
**Post date:** [June 9, 2011, 2:26pm UTC](https://forum.juce.com/t/unrelated-components-on-top-of-each-other/7002/11 "2011-06-09T14:26:03Z")

</div>

> [@jules](#):
>
> I just had a look at ComboBox, and adding a virtual method to create the menu would be a bit awkward because it’d also mean exposing the internal ItemInfo class, and the item list, etc… I’m not really keen to break the encapsulation there.

I never did understand why there is a separate ItemInfo…why not just keep a PopupMenu internally?

---

<div class="post-metadata">

**Author:** ![jules](https://avatars.discourse-cdn.com/v4/letter/j/41988e/32.png) [@jules](https://forum.juce.com/u/jules)\
**Post date:** [June 9, 2011, 2:33pm UTC](https://forum.juce.com/t/unrelated-components-on-top-of-each-other/7002/12 "2011-06-09T14:33:29Z")

</div>

> [@](#):
>
> why not just keep a PopupMenu internally?

Good question. There’s probably a good answer, but I’d have to do some digging to find out - it’s a very long time since I wrote that stuff!
