Matthew Mills
Matthew Mills

Reputation: 103

How to clear netbeans output with code

I was wondering if there was some sort of command I could output that would clear the netbeans output window? I just want the current output to clear, but still have the ability to output more after clearing at run time. Something similar perhaps to BlueJ's:

System.out.print('\u000C');

Upvotes: 0

Views: 8009

Answers (2)

Andika Risky
Andika Risky

Reputation: 11

If you use Netbeans, use this method:

public void clear() throws AWTException {
    Robot rob = new Robot();
    try {
        rob.keyPress(KeyEvent.VK_CONTROL); // press "CTRL"
        rob.keyPress(KeyEvent.VK_L); // press "L"
        rob.keyRelease(KeyEvent.VK_L); // unpress "L"
        rob.keyRelease(KeyEvent.VK_CONTROL); // unpress "CTRL"
        Thread.sleep(1000); // add delay in milisecond, if not there will automatically stop after clear
    } catch (InterruptedException e) {
    }
}

add import java.awt.AWTException; import java.awt.Robot; import java.awt.event.KeyEvent;

Upvotes: 0

Hovercraft Full Of Eels
Hovercraft Full Of Eels

Reputation: 285430

You asked:

I was wondering if there was some sort of command I could output that would clear the netbeans output window?

No, not with a standard console. To do this you need to create either a Swing GUI and clear your text component, use another GUI such as SWT, or use a non-standard 3rd party console.

Upvotes: 1

Related Questions