Painting a component within a component

this is probably just a quick and easy question. i have a sub class of component with its own overriden paint function drawing an image. this sub class also contains a label which i have called addAndMakeVisible, but it doesn’t show up. do I need to explicitly call its paint function in the paint function of the component sublcass that owns it?

some code in case i havent explained it well.

#ifndef _AUROROTARY_
#define _AUROROTARY_

#include "../JuceLibraryCode/JuceHeader.h"

class AuroRotary: public Component
	AuroRotary(String name);
	void mouseDown(const MouseEvent &event);
	void mouseDoubleClick (const MouseEvent& event);
	void paint(Graphics &g);
	void resized();
	Label valuebox;
	Font testFont;

#include "AuroRotary.h"

AuroRotary::AuroRotary(String name):Component(name),valuebox("","slider")
	int i = 0;
	valuebox.setColour(Label::ColourIds::textColourId, Colours::white);

void AuroRotary::resized()

void AuroRotary::paint(Graphics &g)
	Image myStrip = ImageCache::getFromMemory (BinaryData::knob2w65horiz_png, BinaryData::knob2w65horiz_pngSize);	
	g.drawImage(myStrip, 0, 0, 64, 64, 0, 0, 64, 64);
class SlidersAudioProcessorEditor  : public AudioProcessorEditor
	AuroRotary testRotary;
#include "PluginProcessor.h"
#include "PluginEditor.h"

SlidersAudioProcessorEditor::SlidersAudioProcessorEditor (SlidersAudioProcessor* ownerFilter)
    : AudioProcessorEditor (ownerFilter)//,valuebox("","sliders")
    setSize (400, 300);


void SlidersAudioProcessorEditor::resized()


void SlidersAudioProcessorEditor::paint (Graphics& g)
    g.fillAll (Colours::white);
    g.setColour (Colours::black);
    g.setFont (15.0f);


Try calling setOpaque(false) inside your constructor.

that didn’t work, ive also tried commenting out the draw of the image which didn’t do anything.i tried setting a breakpoint in labels paint method. and it didnt get called.

Usually when a component doesn’t appear, it’ll be because you’ve not given it a size, or not added it to the parent, or not made it visible.

1 Like

i’ve done all that, i swapped the code word for word from AuroRotary to the main plugineditor class and the text box displayed. I need it in AuroRotary though.

Well, if your paint method isn’t getting called, it’ll be because it’s off-screen or not visible, or something simple like that.

if that were the case, wouldnt it be offscreen/not visible when i replace the code in the plugineditor class?

i just changed AuroRotarys label and font from static memory to dynamic memory to see if that might help, now the dialog window is completely squashed (as though its height is set to 0) and i cant resize it.

edit: turns out I wasn’t using the correct constructor, doh.