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 259319
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T22:15:15+00:00 2026-05-11T22:15:15+00:00

How to change and update the title of the command prompt window from the

  • 0

How to change and update the title of the command prompt window from the java command line application? Every time I run my application, the command prompt window title shows:
C:\WINDOWS\system32\cmd.exe - java MyApp.

I’d like to change and update the window title as the java program runs, for example as wget(win32) updates downloading status in the title: Wget [12%].

  • 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-05-11T22:15:15+00:00Added an answer on May 11, 2026 at 10:15 pm

    Although I haven’t tried it myself, in Windows, one can use the Win32 API call to SetConsoleTitle in order to change the title of the console.

    However, since this is a call to a native library, it will require the use of something like Java Native Interface (JNI) in order to make the call, and this will only work on Windows 2000 and later.

    Edit – A solution using JNI

    The following is an example of using JNI in order to change the title of the console window from Java in Windows. To implement this, the prerequiste is some knowledge in C and using the compiler/linker.

    First, here’s result:

    Changing the console title from a Java application
    (source: coobird.net)

    Disclaimer: This is my first Java application using JNI, so it’s probably not going to be a good example of how to use it — I don’t perform any error-checking at all, and I may be missing some details.

    The Java program was the following:

    class ChangeTitle {
    
        private static native void setTitle(String s);
    
        static {
            System.loadLibrary("ChangeTitle");
        }
    
        public static void main(String[] args) throws Exception {
    
            for (int i = 0; i < 5; i++) {
                String title = "Hello! " + i;
                System.out.println("Setting title to: " + title);
                setTitle(title);
                Thread.sleep(1000);
            }
        }
    }
    

    Basically, the title is changed every 5 seconds by calling the setTitle native method in an external native library called ChangeTitle.

    Once the above code is compiled to make a ChangeTitle.class file, the javah command is used to create a C header that is used when creating the C library.

    Writing the native library

    Writing the library will involve writing the C source code against the C header file generated by javah.

    The ChangeTitle.h header was the following:

    /* DO NOT EDIT THIS FILE - it is machine generated */
    #include <jni.h>
    /* Header for class ChangeTitle */
    
    #ifndef _Included_ChangeTitle
    #define _Included_ChangeTitle
    #ifdef __cplusplus
    extern "C" {
    #endif
    /*
     * Class:     ChangeTitle
     * Method:    setTitle
     * Signature: (Ljava/lang/String;)V
     */
    JNIEXPORT void JNICALL Java_ChangeTitle_setTitle
      (JNIEnv *, jclass, jstring);
    
    #ifdef __cplusplus
    }
    #endif
    #endif
    

    Now, the implementation, ChangeTitle.c:

    #include <windows.h>
    #include <stdio.h>
    #include <conio.h>
    #include <jni.h>
    #include "ChangeTitle.h"
    
    JNIEXPORT void JNICALL
    Java_ChangeTitle_setTitle(JNIEnv* env, jclass c, jstring s) {
        const jbyte *str;
        str = (*env)->GetStringUTFChars(env, s, NULL);
    
        SetConsoleTitle(str);
    
        (*env)->ReleaseStringUTFChars(env, s, str);
    };
    

    A String that is passed into the native function is changed into an UTF-8 encoded C string, which is sent to the SetConsoleTitle function, which, as the function name suggests, changes the title of the console.

    (Note: There may be some issues with just passing in the string into the SetConsoleTitle function, but according to the documentation, it does accept Unicode as well. I’m not too sure how well the code above will work when sending in various strings.)

    The above is basically a combination of sample code obtained from Section 3.2: Accessing Strings of The Java Native Interface Programmer’s Guide and Specification, and the SetConsoleTitle Function page from MSDN.

    For a more involved sample code with error-checking, please see the Section 3.2: Accessing Strings and SetConsoleTitle Function pages.

    Building the DLL

    The part that turned out to take the most amount of time for me to figure out was getting the C files to compile into an DLL that actually could be read without causing an UnsatisfiedLinkError.

    After a lot of searching and trying things out, I was able to get the C source to compile to a DLL that could be called from Java. Since I am using MinGW, I found a page form mingw.org which described exactly how to build a DLL for JNI.

    Sources:

    • The Java Native Interface Programmer’s Guide and Specification
      • Chapter 2: Getting Started – Details the process using JNI.
    • JNI-MinGW-DLL – Building a JNI DLL on MinGW with gcc.
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Is there a quick console command I can run to change the type I
I have this code: $('.update-title') .change(function () { $(this).prop('title', $('option:selected', this).prop('title')); }); and this
I have the following code: $('#modal .update-title') .change(function () { var title = $('option:selected',
I have the following code for a normal select list: $('.update-title') .change(function () {
Using the update command, I want to change the type_name for a specific entry
I'm trying to find a way to change/update a model inside a collection without
I would like to update (change the content) some part of the webpage without
I'm trying to update/change contact ringtone using this code: ContentValues values = new ContentValues();
I want to update a Post and change relationships with Categories that already created
I am trying to change QTreeView with a auto update and I am able

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.