23

広範囲にわたって検索しましたが、機能するものが見つかりませんでした...方法があります!!! したがって、必要なのは、Eclipseのコンソールをクリアする(空白にする)コードです。いいえ、50行の空白行を印刷せず、クリアします。

私はこれを見つけました:

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();
    }

しかし、それは私にエラーを与えます:「メソッドclear()はタイプConsoleに対して未定義です

4

2 に答える 2

14

Eclipseツールでは、右クリックしてコンソールパネルをクリアできますが、Javaではクリアできません。

コンソールはログツールであり、管理セキュリティのためにクリアすることはできません。

于 2012-05-09T06:41:44.550 に答える
14

私は答えに遅れるかもしれませんが、これが私が何とかしたことです(そしてそれは私のために働きました):

このチュートリアルhttp://wiki.eclipse.org/FAQ_How_do_I_write_to_the_console_from_a_plug-in%3Fに基づいてコンソールを作成し、findConsoleメソッドを次のように変更しました。

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;
   }

だから、他のボタン/コントロール/何でものリスナーで、私は持っています:

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

そして、そのコードが実行されるたびに、私のコンソールはクリアされます。それが役に立てば幸い。

編集:言及するのを忘れました、私はRCPアプリケーションを作成するときにこれをしました!

于 2013-04-08T15:09:31.603 に答える