Basically I have a JFrame for a simple text editor.
The filename you’re working on appears in the title.
So I set up some code to change the title when necessary and it gets called fine.
The problem is after the code is called the JFrame title won’t change. the getTitle() function and everything shows the title as being changed. it’s only when you loose focus on the JFrame that the title actually graphically changes.
A quick and dirty (very much so) fix I implemented was toBack() followed by toFront() effectively forcing you to lose focus – and this does the trick in a very ugly way.
I have tried invalidate() and validate(), various repaint() calls, and setVisible(true) yet none of them do the trick.
I’ve done some searching and can’t seem to find a solution, it’s a small error but an annoying one. Does anyone have some insight?
Here’s the code I use
private void() updateTitle() {
setTitle(((filename == null) ? "untitled" : filename) + ((unsaved) ? "*" : ""));
toBack();
toFront();
}
and this is all inside a class that extends JFrame.
edit:
Worth mentioning that there are no loops or threads or anything tying up the EDT. Just plain and simple stuff. Disabled all the listeners and everything to try and debug this. SetTitle is being called NOWHERE else in the program. If i print the getTitle() result to the console it will tell me the title that should be displayed but isn’t displayed until focus is lost on the window
edit2:
It turns out it was just an error in my jdk. reinstalling the jdk fixed the problem. Sorry for misleading you guys, and thanks for your responses.
This simple example (just calling
setTitle()) worked for me:One thing to be careful of: you should call
setTitle()while on the Event Dispatch Thread.Adjusting your method as follows may help: