Looking for an efficient Java Swing based console

隐身守侯 提交于 2019-12-29 06:24:13

问题


I'm looking for a highly efficient Swing Java component which I can just plug into my application UI. I already tried using the classes within Swing such as JTextArea with no avail; they simply aren't high-performance enough and have any crippling drawbacks. Additionally, it'd be nice if it had standard console features such as scroll-lock, clear console, colours, and so on.

Edit: Forgot to say, this console will have a lot of debug information streaming into it, and it needs to be fully scrollable.

Cheers,
Chris


回答1:


I fail to see what is wrong with using a JTextPane. It supports attributes which you can specify as each piece of text is added to the console. Clearing it is also obviously a no brainer. When added to a scroll pane it also supports scrolling.

You can add scroll locking by using Smart Scrolling.

Plus, it removes text too early and

No idea what that means as text is never removed unless you specifically remove it from the document.

doesn't allow the user to scroll while input is being entered (afaik). The effect is that you just see text flashing while the number of rows remains the same.

By default the text scrolls automatically as text is append to the document assuming the code is executed on the EDT. This scrolling can be controlled the the example provided in the link above.

Edit:

but I'd still like a library solution

I don't know of any

auto-colourise text coming from different streams

The Message Console might give you some ideas.

(i.e., detect [error] prefix on a line) and colourise lines based on this)

This is easily done by adding a DocumentFilter to the Document of the text pane. You can add attributes as text is inserted into the Document.




回答2:


Be sure that you read about the Event Dispatching Thread (EDT) in swing!

BTW: a simple search 'java swing console' will give you a lots of hints OR you could use/adapt the beanshell textfield which is a jtextfield too ...



来源:https://stackoverflow.com/questions/2329455/looking-for-an-efficient-java-swing-based-console

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!