# TextEditor Alignment

**URL:** <https://forum.juce.com/t/texteditor-alignment/12885>\
**Category:** General JUCE discussion\
**Created:** [May 21, 2014, 4:24pm UTC](https://forum.juce.com/t/texteditor-alignment/12885 "2014-05-21T16:24:38Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![pvaz](https://avatars.discourse-cdn.com/v4/letter/p/3ec8ea/32.png) [@pvaz](https://forum.juce.com/u/pvaz)\
**Post date:** [May 21, 2014, 4:24pm UTC](https://forum.juce.com/t/texteditor-alignment/12885/1 "2014-05-21T16:24:38Z")

</div>

Hi,

&nbsp;

seems that this is a subject that was already posted before, but i could not see in the posts any solution.

How can I make a TextEditor component to have the text align right or centered, since by default if left alignment.

&nbsp;

Thanks,

Paulo

---

<div class="post-metadata">

**Author:** ![rory](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/rory/32/534_2.png) [@rory](https://forum.juce.com/u/rory)\
**Post date:** [May 22, 2014, 4:02pm UTC](https://forum.juce.com/t/texteditor-alignment/12885/2 "2014-05-22T16:02:19Z")

</div>

As far as I know there is no way to do this. If you only need a basic texteditor then you could draw one yourself, maybe you could use the paintOverChildren() method along with a drawFittedText(). But if it's a fully functional editor you need, with text alignment, I don't think that is possible yet.

---

<div class="post-metadata">

**Author:** ![dschiller](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/dschiller/32/9620_2.png) [@dschiller](https://forum.juce.com/u/dschiller)\
**Post date:** [August 19, 2024, 9:11pm UTC](https://forum.juce.com/t/texteditor-alignment/12885/3 "2024-08-19T21:11:42Z")

</div>

You can use the `setJustification()` method.

### PropertyTextEditor.h

```cpp
#pragma once

#include <JuceHeader.h>

class PropertyTextEditor : public juce::TextEditor
{
public:
    PropertyTextEditor(const juce::String& name);
    ~PropertyTextEditor() override = default;
    
    void paint(juce::Graphics& g) override;
    void paintOverChildren(juce::Graphics& g) override;
    
private:
    JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR(PropertyTextEditor)
};

```

### PropertyTextEditor.cpp

```cpp
#include "PropertyTextEditor.h"

PropertyTextEditor::PropertyTextEditor(const juce::String& name) {
    setBounds(0, 0, 104, 31);
    auto typeface = juce::Typeface::createSystemTypefaceFor(Assets::RobotoMonoRegular_ttf, Assets::RobotoMonoRegular_ttfSize);
    juce::FontOptions options(typeface);
    juce::Font font(options);
    font.setHeight(21.f);
    setFont(font);
    setColour(textColourId, juce::Colour(0xfffff95e));
    applyFontToAllText(font);
    setColour(highlightColourId, juce::Colour(0xfffff95e));
    setColour(highlightedTextColourId, juce::Colour(0xff111111));
    setJustification(juce::Justification::topRight);
    setCaretVisible(true);
    int caretColourId = 0x1000204;
    setColour(caretColourId, juce::Colour(0xff0084ff));
    InputFilter *filterNumbersOnlyLengthFour = new LengthAndCharacterRestriction(4, "0123456789");
    setInputFilter(filterNumbersOnlyLengthFour, true);
}

void PropertyTextEditor::paint(juce::Graphics& g) {
    g.setColour(juce::Colour(0xff444444));
    g.fillRoundedRectangle(0, 0, getWidth(), getHeight(), 5);
}

void PropertyTextEditor::paintOverChildren(juce::Graphics& g) {
    
}

```

 ![Screenshot 2024-08-19 at 23.08.56](https://us1.discourse-cdn.com/flex026/uploads/juce/original/3X/6/2/62104eb0535777d4beb51b241cafc6dd00b1305d.png)

---

<div class="post-metadata">

**Author:** ![mjokipii](https://avatars.discourse-cdn.com/v4/letter/m/e47c2d/32.png) [@mjokipii](https://forum.juce.com/u/mjokipii)\
**Post date:** [October 26, 2024, 3:26pm UTC](https://forum.juce.com/t/texteditor-alignment/12885/4 "2024-10-26T15:26:07Z")

</div>

This actually works very well. Some additional adjustment with the indents and voila.

This is what i needed.

```auto
class CustomLabel : public juce::Label {
	public:
		CustomLabel () = default;
		juce::TextEditor* createEditorComponent () override;

	private:
		JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (CustomLabel)
		};

```

```auto
juce::TextEditor* CustomLabel::createEditorComponent () {
	auto editor = std::make_unique<juce::TextEditor> ();
	editor->setJustification (juce::Justification::Flags::centredRight);
	editor->setFont (getFont ());
	editor->setIndents (0, 0);
	return editor.release ();
}

```
