Close the SwingTerminal by clicking on 'x' (close) or with standard shortcut

684 views
Skip to first unread message

Laurent Schwartz

unread,
Mar 22, 2013, 7:29:17 AM3/22/13
to lanterna...@googlegroups.com
Hi Martin,

When my application runs in Swing Terminal, i would like to be able to close the window by clicking on 'X' or by pressing ALT+F4 shortcut to close windows on Unity.

In graphical environment, there are standards and i don't want to break them.

Is it possible to implement the close window feature for Swing Terminal window ?

Regards,
Laurent

Martin Berglund

unread,
Mar 26, 2013, 7:53:19 AM3/26/13
to lanterna...@googlegroups.com
Yes, you can get the underlying JFrame from the SwingTerminal and register a close listener. I guess ideally the close listener should properly close SwingTerminal (causing the window to go away) rather than calling .setVisible(false) on the JFrame.

Thanks,
Martin

2013/3/22 Laurent Schwartz <elea...@gmail.com>

--
Det här meddelandet skickas till dig eftersom du prenumererar på gruppen lanterna-discuss i Google Groups.
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/groups/opt_out.
 
 

Laurent Schwartz

unread,
Mar 27, 2013, 5:31:44 PM3/27/13
to lanterna...@googlegroups.com
Hi Martin,

i added a Window Listener with closing method on the JFrame of the Swing Terminal.

The closing method call nicely the main lanterna window close() method thus exiting SwingTerminal.

Regards,
Laurent

Guy Marom

unread,
Apr 8, 2013, 2:36:24 PM4/8/13
to lanterna...@googlegroups.com
Why doesn't this work with a Screen object? pressing Alt+F4 doesn't return anything in screen.readInput.
Thanks

Guy Marom

unread,
Apr 8, 2013, 11:33:34 PM4/8/13
to lanterna...@googlegroups.com
Pressing the windows "X" also does nothing

Nicolas Pellegrin

unread,
Apr 11, 2013, 10:13:26 AM4/11/13
to lanterna...@googlegroups.com
Hi,

Alt+F4 is catched by the system, you can't get it from screen.readInput
The solution given previously works for both gui layer and screen layer. To handle Alt+F4 and "X" button in a graphical environment you can do something like this:

// Create objects
SwingTerminal swingTerminal = new SwingTerminal();
final Screen myScreen = new Screen(swingTerminal);

// Start screen,  display SwingTerminal
myScreen.startScreen();

// Add a window listener to the SwingTerminal JFrame
swingTerminal.getJFrame().addWindowListener(new java.awt.event.WindowAdapter() {
    public void windowClosing(java.awt.event.WindowEvent evt) {
        myScreen.stopScreen();
      }
});

Nicolas.

Martin Berglund

unread,
Apr 20, 2013, 4:44:12 AM4/20/13
to lanterna...@googlegroups.com
Thank you Nicolas, yes, that's pretty much it.

Martin


2013/4/11 Nicolas Pellegrin <npelleg...@gmail.com>

Kamil

unread,
Oct 9, 2016, 8:35:44 AM10/9/16
to lanterna-discuss
It doesn't work.
The SwingTerminal don't have method like getJFrame();
Please write something more about topic.

AvL42

unread,
Oct 21, 2016, 6:52:05 PM10/21/16
to lanterna-discuss
For this you won't use the DefaultTerminalFactory, but instead create an instance of SwingTerminalFrame .

This instance then *is* the JFrame, and it also *is* the Terminal that you can use as argument for creating the TerminalScreen.

Reply all
Reply to author
Forward
0 new messages