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"
out. print(ESC + "2J"); Also, you can print multiple end of lines ("\n") and simulate the clear screen.
public static void clrscr(){ //Clears Screen in java.
To clear the console, clrscr() is used.
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.
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!
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With