我在 Windows 上使用 NetBeans IDE 和 lanterna 。我尝试创建一个 SwingTerminal,但它不会显示。
public static void main(String[] args) throws Exception {
SwingTerminal t = TerminalFacade.createSwingTerminal();
while (true) {
Thread.sleep(100);
}
}
我也尝试显示 JFrame,但我从 SwingTerminal.getJFrame()
得到 null
。
t.getJFrame().setVisible(true);
我还尝试从命令行运行该程序,认为这可能是 NetBeans 的问题,但它也不起作用 (cygwin)。如何使 SwingTerminal 显示?
最佳答案
我应该先看看 Google 讨论。由一堆片段拼凑而成:
public static void main(String[] args) {
// Create a Terminal and Screen.
SwingTerminal terminal = new SwingTerminal();
Screen screen = new Screen(terminal);
screen.startScreen();
// Add listener(s) for the Window. The JFrame won't shut
// down itself when Alt+F4 or the like is pressed or the
// Window is closed by pressing the X button.
terminal.getJFrame().addWindowListener(
new java.awt.event.WindowAdapter() {
public void windowClosing(java.awt.event.WindowEvent evt) {
screen.stopScreen();
}
}
);
}
关于java - Lanterna SwingTerminal 不会显示,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27955944/