Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to clear console in Java - Eclipse SDK [duplicate]

Tags:

I've searched far and wide, but haven't found something that works... There HAS to be a way!!! So, what I need is a code that clears the console in Eclipse (makes it blank). And NO, not printing 50 blank lines, CLEARING IT!

I found this:

Import import java.io.Console;  public void ClearConsole() {             Console console = System.console();                     if (console == null)                     System.out.println("Couldn't get Console object !");             console.clear();     } 

But it gives me an error: "The method clear() is undefined for the type Console"

like image 743
Vanya Burduk Avatar asked May 09 '12 03:05

Vanya Burduk


People also ask

How do I clear the console in Eclipse?

out. print(ESC + "2J"); Also, you can print multiple end of lines ("\n") and simulate the clear screen.

What is Clrscr () in Java?

public static void clrscr(){ //Clears Screen in java.

Which code is used to clear the console?

To clear the console, clrscr() is used.


2 Answers

In Eclipse tool you can clear the console panel by right clicking + clear but not in Java.

Console is a log tool, it cannot be cleared for administration security.

like image 55
cl-r Avatar answered Oct 19 '22 17:10

cl-r


I may be late with my answer, but here is what I managed to do (and it worked for me):

I created my console based on this tutorial http://wiki.eclipse.org/FAQ_How_do_I_write_to_the_console_from_a_plug-in%3F , and modified the findConsole method to look like this:

private MessageConsole findConsole(String name) {        ConsolePlugin plugin = ConsolePlugin.getDefault();       IConsoleManager conMan = plugin.getConsoleManager();        IConsole[] existing = conMan.getConsoles();       //if console exists, clear it        for (int i = 0; i < existing.length; i++)           if (name.equals(existing[i].getName())){               ((MessageConsole) existing[i]).clearConsole(); //this is the important part               return myConsole;           }        myConsole = new MessageConsole(name, null);       conMan.addConsoles(new IConsole[]{myConsole});       return myConsole;    } 

So, in the listener of some other button/control/whatever, I have:

myConsole = findConsole(ASIO_RECORD_OUTPUT); myConsoleOut = myConsole.newMessageStream(); 

and whenever that piece of code gets executed, my console is cleared. Hope it helps.

edit: Forgot to mention, I did this when creating an RCP application!

like image 22
deckard cain Avatar answered Oct 19 '22 18:10

deckard cain