Changing Titlebar text - *Solved*

Hey, I’m trying to have the filename of an open text file displayed on the titlebar. Since I’m new to juce, this is probably a really easy answer.

[code]if (browsewin.browseForFileToOpen())
{
filename = browsewin.getResult();
text->setText(filename.loadFileAsString());

apptitle = T(" | JUCE Text Viewer");
filetitle = filename.getFileName();
newapptitle.operator = (filetitle);
newapptitle.operator += (apptitle);

//I'm about 78% sure that the next line is where I'm screwing up
DocumentWindow::setName( newapptitle );

}[/code]

Also, the reason apptitle literally has the name is because I couldn’t get getApplicationName() to work for some reason.

Any help would be greatly appreciated.

newapptitle.operator = (filetitle);
newapptitle.operator += (apptitle);

You know you can just do it like this right?

newapptitle = filetitle;
newapptitle += apptitle;

or even easier

newapptitle = filename.getFileName() + T (" | JUCE Text Viewer");

But about your actual question, I don’t know

Using DocumentWindow::setName does change the string in the title bar. You do seem to be writing 10 times more code than is necessary, though!

setName (browsewin.getResult().getFileName() + T (" | JUCE Text Viewer"));

would do the same thing in one line!

Wow, thanks for the quick replies!

When using the above, the titlebar doesn’t actually change. Is there some sort of a repaint() I need to call to refresh the titlebar?

I just tried it and it works, you must have a problem elsewhere.

Well then. Just to see if I could get the titlebar to change, I took the Hello World app and modified it. I was unable to get it to change. Please take a look through and see if there is something really stupid I’m doing, heh.

[code]class HelloWorldContentComponent : public Component, ButtonListener
{
private:
TextButton* tbutton;
String text;
public:
HelloWorldContentComponent()
{
tbutton = new TextButton (T(“Click to test TitleBar”));
addAndMakeVisible( tbutton );
tbutton->setBounds( 5, 5, 0, 40);
tbutton->addButtonListener(this);
tbutton->changeWidthToFitText();

	text = T("Hello World");
}

~HelloWorldContentComponent()
{
	deleteAllChildren();
}

void buttonClicked (Button* button)
{
	if (button == tbutton)
	{
		if ( text.contains( T("Hello")))
		{
			setName( T("New Titlebar Text"));
			text = T("The button works if you see this.");
			repaint();
		}
		else
		{
			setName( T("Hello World"));
			text = T("Hello World");
			repaint();
		}
	}
}

void paint (Graphics& g)
{
    	g.fillAll (Colours::white);
        g.drawText (text,
           	    0, 0, getWidth(), getHeight(),
                Justification::centred, false);
}

};[/code]

I only included that part because I left the rest of “Hello World” untouched. The button works fine, the text changes between “hello world” and “button works…” but the title bar text remains steadfastly stuck at “Hello World”.

That’s because you’re not actually changing the name of the window. You’re changing the name of the content component.

Alright, so what should I be doing?

Well, you should be changing the name of the window instead of the content component…

A simple way to get a pointer to the window in this case would be with getTopLevelComponent() - you could say:

getTopLevelComponent()->setName (blah blah)

You, sir, are my hero. Many thanks to you for JUCE, and many more for helping people to use it. Also, thanks go to G-Mon for shortening my madness.

Problem Solved

I’m sorry, I know this was an old post, but I’m having the same problem, and I can’t get it to work.

I tried the suggestion above:
getTopLevelComponent()->setName(“NEW TITLE”);
in the editor constructor.

And also when my main window is added:
gui->windowMain->getTopLevelComponent()->setName(“NEW TITLE”);
addAndMakeVisible(gui->windowMain);

But nothing happens.

The application title bar says: “BINARYNAME/1-BINARYNAME”

Please help.

Is this Windows or Mac and are you using a Native title bar?

Rail

This thread is 1 day away from being 10 years old!!!

Blast from the past…

I’m running on Windows 7, Visual Studio 2012 Express, target is VST, Projucer Version 4.3.0.

I’m not sure if its a “Native” title bar, I’m justing using what ever title bar JUCE created by default.
Based on over 20 years experience with Win Forms and MFC, I’d say it looks like a native title bar.

Actually I’d like to get rid of the title bar altogether but that is a whole separate question.

I could easily debug it myself if it involved one of the defines in JUCE’s AppConfig.h, since many of the fields from the Projucer Config page translate into these defines. But the JUCE Debug/Release “Binary name” is what is being used, and that translates into a Visual Studio properties setting “Target Name” so I have nothing to search for in the JUCE source to find where the string is being constructed.

If the title bar just used the target name I would just leave it alone, but it is saying “synthname/Notes” on the title bar, and sometimes “synthname/1-synthname” which I don’t want at the top of my released plugin.

I’ve tried changing the JUCE “Notes” field to something, but it still just says “/Notes”.

I’ve even tried searching for any kind of string formation such as + "/Notes, or even + "//, but nothing comes up for the title bar.

I think maybe JUCE is just letting WIn Forms create its own title bar.

All I need is some idea where in JUCE to look and I could fix it myself.

Thanks for responding !!!

If this is a plugin the window is usually owned by the host and it sets the title bar text… or is this a child window?

Rail

1 Like

Your question solved the problem for me.

The border title text is being set by the Host (Ableton), not JUCE,
and is comprised of the: PlugginName)/TrackName.

The extra text I did not recognize was the host track name.

Sorry !