I was able to to figure out a "solution". I noticed that if in the try block I set the value of the textbox to "" then the GUI doesn't quit on me. Below is my test case code:
import com.googlecode.lanterna.*;
import com.googlecode.lanterna.screen.*;
import com.googlecode.lanterna.bundle.*;
import com.googlecode.lanterna.TerminalSize;
import com.googlecode.lanterna.gui2.*;
import com.googlecode.lanterna.gui2.dialogs.*;
import com.googlecode.lanterna.gui2.Window.Hint;
import com.googlecode.lanterna.gui2.dialogs.MessageDialog;
import com.googlecode.lanterna.graphics.*;
import com.googlecode.lanterna.terminal.*;
import com.googlecode.lanterna.terminal.ansi.*;
import java.io.*;
import java.util.*;
import java.nio.charset.*;
import java.util.regex.*;
public class testCase {
public static void main(String[] args) throws IOException {
new testCase().run(args);
}
public void run(String[] args) throws IOException {
Terminal terminal = new UnixTerminal(System.in,
System.out,
Charset.defaultCharset(),
UnixLikeTerminal.CtrlCBehaviour.CTRL_C_KILLS_APPLICATION);
Screen screen = new TerminalScreen(terminal);
screen.startScreen();
MultiWindowTextGUI textGUI = new MultiWindowTextGUI(new SeparateTextGUIThread.Factory(), screen);
textGUI.setBlockingIO(false);
textGUI.setEOFWhenNoWindows(true);
textGUI.isEOFWhenNoWindows();
Panel contentPanel = new Panel(new GridLayout(2));
try {
BasicWindow bw = new BasicWindow("testcase");
TextBox textBox = new TextBox();
textBox.setValidationPattern(Pattern.compile("^[a-z]{0,5}$"));
try {
textBox.setText("9");
} catch(IllegalStateException e) {
StringWriter sw = new StringWriter();
e.printStackTrace(new PrintWriter(sw));
String exceptionAsString = sw.toString();
// write exception to a file
FileWriter wr = new FileWriter("err");
wr.write( exceptionAsString);
wr.close();
// this worked for me
textBox.setText("");
}
textBox.setLayoutData(GridLayout.createLayoutData(
GridLayout.Alignment.BEGINNING, // Horizontal alignment in the grid cell if the cell is larger than the component's preferred size
GridLayout.Alignment.BEGINNING, // Vertical alignment in the grid cell if the cell is larger than the component's preferred size
true, // Give the component extra horizontal space if available
false, // Give the component extra vertical space if available
1, // Horizontal span
1)); // Vertical span
contentPanel.addComponent(textBox);
bw.setHints(Arrays.asList(Window.Hint.FULL_SCREEN));
bw.setComponent(contentPanel);
textGUI.addWindow(bw);
AsynchronousTextGUIThread guiThread = (AsynchronousTextGUIThread)textGUI.getGUIThread();
guiThread.start();
guiThread.waitForStop();
} catch (Exception e) {
e.printStackTrace();
}
finally {
screen.stopScreen();
System.exit(0);
}
} // end of run()