How to properly close/stop a Lanterna program?

323 views
Skip to first unread message

Maarten Boekhold

unread,
Mar 28, 2016, 9:57:44 AM3/28/16
to lanterna-discuss
Hi,

I'm experimenting a bit with Lanterna 3.0.0-beta2, and I'm running some code as a Unit Test inside IntelliJ, basically the equivalent of the very first example in the docs. When I close the SwingTerminalFrame, the Unit Test keeps running. What would be the proper way to shut down:

gui.addWindowAndWait(window)...

on closing of the SwingTerminalFrame?

Maarten

ps. I'm actually experimenting with creating a groovy DSL for this. The Griffon project has one, but that cannot be used stand-alone, only as part of a Griffon project. I've got a minimal example up-and-running, including IDE code completion:

        def terminal = new LanternaTerminalBuilder().build() {
            window
{
                panel
{
                    border
(style: 'singleLine', title: 'Main panel')
                    gridLayout
(2)
                    label
('My First Little Label')
               
}
           
}
       
}

        terminal
.waitFor()


Martin Berglund

unread,
Mar 28, 2016, 11:12:44 AM3/28/16
to lanterna...@googlegroups.com
Hi Maarten,
Is the problem that the AWT thread is not shutting down or is it that your addWindowAndWait is never finishing? If the former, try calling the exit private mode method on the terminal, that should dispose the SwingTerminalFrame (you can also manually call dispose on it). If the latter, just make sure to call close on the window and the method should come return.

Thanks,
Martin

--
Det här meddelandet skickas till dig eftersom du prenumererar på gruppen "lanterna-discuss" i Google Grupper.
Om du vill sluta prenumerera på den här gruppen och inte längre få någon e-post från den skickar du ett e-postmeddelande till lanterna-discu...@googlegroups.com.
Fler alternativ finns på https://groups.google.com/d/optout.

Maarten Boekhold

unread,
Mar 28, 2016, 11:40:09 AM3/28/16
to lanterna-discuss
Hi,

gui.addWindowAndWait(window) never finishes, not even after I (forcebly) close the window by clicking on the close button (top right). How can I detect that?

Maarten

Maarten Boekhold

unread,
Mar 29, 2016, 2:30:27 AM3/29/16
to lanterna-discuss
Hi

Basically it seems that if you close the SwingTerminal (SwingTerminalFrame?), the underlying AWT thread is not stopped? I can't find a "windowClosing()" method anywhere in the Lanterna code. Am I supposed to handle this manually/explicitly?

Maarten

Maarten Boekhold

unread,
Mar 31, 2016, 4:58:37 AM3/31/16
to lanterna-discuss
To answer myself, set the "defaultCloseOperation" on the SwingTerminal to "WindowConstants.DISPOSE_ON_CLOSE"

Maarten

Martin Berglund

unread,
Apr 1, 2016, 9:53:01 AM4/1/16
to lanterna...@googlegroups.com
Swing works this way. Closing a Swing window doesn't terminate the AWT thread unless you dispose it either through DISPOSE_ON_CLOSE or .dispose().
In Lanterna-space, addWindowAndWait() will block until you call .close() on that window.

Martin
Reply all
Reply to author
Forward
0 new messages