How to change command prompt (console) window title from command line Java app?

后端 未结 4 1117
南旧
南旧 2020-12-17 22:24

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 show

4条回答
  •  無奈伤痛
    2020-12-17 22:50

    Here's my solution using JNA:

    import com.sun.jna.Library;
    import com.sun.jna.Native;
    import com.sun.jna.Platform;
    
    public class SetTitle {
    
        public interface CLibrary extends Library {
            CLibrary INSTANCE = (CLibrary)
                Native.loadLibrary((Platform.isWindows() ? "kernel32" : "c"),
                                   CLibrary.class);
    
            boolean SetConsoleTitleA(String title);
        }
    
        public static void main(String[] args) {
            CLibrary.INSTANCE.SetConsoleTitleA("Testing 123");
            System.exit(0);
        }
    }
    

提交回复
热议问题