How to clear console in Java - Eclipse SDK

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!


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.

Tags:

Java