简体   繁体   English

JVM / Swing GUI应用程序应如何显示控制台?

[英]How should JVM/Swing GUI application show console?

The application creates and displays various Swing widgets, and also writes debugging messages to System.out. 应用程序创建并显示各种Swing小部件,并将调试消息写入System.out。 If I start it as java -jar ...jar then I see it, but if I click on jar file in GUI I don't see the console. 如果我把它作为java -jar ...jar启动然后我看到它,但如果我点击GUI中的jar文件我看不到控制台。 How to make it show console to user explicitly, eg on reaction to "View -> Debug output" menu item? 如何使它明确地向用户显示控制台,例如对“视图->调试输出”菜单项的反应?

Expecting something that will pop up cmd.exe window on Windows, xterm/... on Linux, but it may be Swing window as well. 可能会在Windows上弹出cmd.exe窗口,在Linux上弹出xterm / ...,但也可能是Swing窗口。 How to do it the easily? 怎么做容易?

First don't use System.out to log , use some Logging framework to write logs in some file and to display the debugging logs open a new JDialog with JTextArea or JTextPane in it. 首先不要使用System.out进行日志记录 ,使用一些Logging框架在一些文件中写入日志,并显示调试日志,打开一个带有JTextArea或JTextPane的新JDialog。 Read the log file content and display that in the textArea. 读取日志文件的内容,并将其显示在textArea中。 This way it will also solve platform dependency. 这样它也将解决平台依赖性。

我认为你在寻找CTRL + SHIFT + F1工作如果GUI在这里可见你可以看到输出到控制台, JComponents Tree层次结构

AFAIK on Windows the console would be displayed on the first console output (ie System.out.printXXX), while on Linux it must be executed from console itself to do so. Windows上的AFAIK控制台将显示在第一个控制台输出(即System.out.printXXX)上,而在Linux上则必须从控制台本身执行才能执行此操作。 I'd rather create a separate window with a JTextArea (or something similar) to display the debug output. 我宁愿用JTextArea(或类似的东西)创建一个单独的窗口来显示调试输出。 Normal users won't care about / need it, right? 普通用户不会关心/需要它,对吧?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM