Override TextEditor

I am trying to override the text editor for use as a login box.


#include “juce.h”

class UidBox : public TextEditor

	UidBox(): TextEditor ()





UidBox * uidBox = new UidBox;
startWindow->addAndMakeVisible (uidBox);
uidBox->setBounds (106, 270, 202, 20);
uidBox->setText (T(“testcase”));

Compiles file, but the box is not visible. What am I doing wrong?


Sounds fine, but what sort of window are you adding it to? Maybe the parent comp isn’t visible, or the box is off the edge, or covered by another component or something?

The window is visible as are other components on the page:

class StartWindow : public Component
StartWindow() : Component (T(“AV”))
setOpaque (true);
setVisible (true);
addToDesktop (ComponentPeer::windowAppearsOnTaskbar | ComponentPeer::windowHasDropShadow);
centreWithSize (640, 480);


What I want to do is add a text box to the page and then grab the current text in the box when I click a button. When I try to get to the text inside the button’s click() function I can’t do it.

You don’t need to grab it in the button’s click function.

I presume your component has the button and text editor as members.
Your component should be a ButtonListener (to recieve click messages from the button), and registered with the button via myButton->addButtonListener(this) in your component’s constructor.

You then have a buttonClicked (Button* b) function to implement, in which you test that it was that button [ if (b == myButton) { … } ] and then do what you want from there, e.g. doStuffWith (myEditor->getText ());

You likely don’t want to be using addToDesktop either… you should be using something like a DialogWindow or DocumentWindow if you want to have it appear on the desktop (or perhaps even just using an AlertWindow subclass).

what is it that you want to actually do? do you have a sketch of how you want it to look?

Have you tried using the jucer to create the component with the text box and button on there? That’s an easier way to start off than doing it all by hand.