Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7774209
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T17:19:12+00:00 2026-06-01T17:19:12+00:00

Basically I have a JFrame for a simple text editor. The filename you’re working

  • 0

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.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-01T17:19:14+00:00Added an answer on June 1, 2026 at 5:19 pm

    This simple example (just calling setTitle()) worked for me:

    import java.awt.event.ActionEvent;
    import java.awt.event.ActionListener;
    
    import javax.swing.JButton;
    import javax.swing.JFrame;
    
    public class Frame2
    {
        public static void main( String[] args )
        {
            final JFrame frame = new JFrame( );
    
            JButton button = new JButton( "press me" );
            button.addActionListener( new ActionListener( )
            {
    
                @Override
                public void actionPerformed( ActionEvent e )
                {
                    frame.setTitle( "New Title" );
                }
    
            } );
    
            frame.setTitle( "Title" );
            frame.add( button );
            frame.setSize( 400, 400 );
            frame.setVisible( true );
        }
    }
    

    One thing to be careful of: you should call setTitle() while on the Event Dispatch Thread.

    Adjusting your method as follows may help:

    private void() updateTitle() {
      SwingUtilities.invokeLater( new Runnable()
      {
        @Override
        public void run( )
        {
          setTitle(((filename == null) ? "untitled" : filename) + ((unsaved) ? "*" : ""));
        }
      });
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Basically, I have a JTextPane to hold some text which I wish to style.
I basically have a unix process running and it is doing some heavy processing
I basically have a server set up and I'm accepting new clients(UNIX) and i'm
I basically have to do a update of a record. I have a set
Basically I have a GUI that inherits from the JFrame class and has its
I will try to keep this as simple as possible. Basically I have a
When I run my code it doesn't show up. Basically I have a custom
Basically I plan to place some buttons, textfields, labels, etc. on a JFrame and
I basically have: Public Class Job: MyBaseClass { public virtual string JobInformation {get;set;} ...
Basically my entire program is to have shapes move across a JFrame, and the

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.