Is there any way by which I can clear the screen (terminal window)?
I used to use the "\u000c" escape sequence in BlueJ and it used to work fine but in JCreator, it displays a box.
Welcome to the Java Programming Forums
The professional, friendly Java community. 21,500 members and growing!
The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.
>> REGISTER NOW TO START POSTING
Members have full access to the forums. Advertisements are removed for registered users.
Is there any way by which I can clear the screen (terminal window)?
I used to use the "\u000c" escape sequence in BlueJ and it used to work fine but in JCreator, it displays a box.
In pure Java, no.
If it is sufficient that my program works on Windows, is there any way ( and more specifically, exceuting it from JCreator) . I mean that my program need not run on all platforms, windows is sufficient.
If you only want to give the appearance of a cleared screen, just print out a lot of new lines. The text will likely still be around, but you'll have to scroll very far up to see it. This is generally not recommended because it's slow and not fool proof.
Otherwise, I doubt you'll be able to since I believe JCreator uses a GUI textbox element to show the text output and there's no way to access this text box directly without hacking into JCreator (not recommended).
If your program being run from a terminal (command prompt, bash, xterm, etc.), the best way is to use either JNI or JNA to interface with native C++ code. See Clear the screen - OS Specific Ways for how to write the C++ code.
Last edited by helloworld922; March 18th, 2012 at 03:52 PM.
As helloworld922 says, you cannot do this in pure java because java is OS independent and clearing the console is an OS function.
Whenever I wish to emulate the behavior I use this:
public void clearScreen() { for (int i = 0; i < 16; i++) System.out.println(); }
It is dirty and (as above) problematic but it gets the job done. A pure hack.