Trying to clear the output window in NetBeans: CTRL + L works, and so I am trying to recreate that command using awt.Robot. I've looked around and tried System.out.flush();
which didn't work. I don't want to print new lines.
Here is my test code:
package test;
// import Robot, KeyEvent & AwtException
import java.awt.AWTException;
import java.awt.Robot;
import java.awt.event.KeyEvent;
public class Test {
public static void main(String[] args) throws AWTException, InterruptedException {
// print text to output
System.out.println("Hello World!");
// initialize new robot, "keyPresser"
Robot keyPresser = new Robot();
// hold & release CTRL + L to theoretically clear the output window
keyPresser.keyPress(KeyEvent.VK_CONTROL);
Thread.sleep(500);
keyPresser.keyPress(KeyEvent.VK_L);
Thread.sleep(500);
keyPresser.keyRelease(KeyEvent.VK_CONTROL);
Thread.sleep(500);
keyPresser.keyRelease(KeyEvent.VK_L);
Thread.sleep(500);
}
}
Am I on the right track? Is this the wrong way to go about this? What other options could I use to clear the output window?