获取DocumentListener的间接源 [英] Getting indirect source of DocumentListener

查看:69
本文介绍了获取DocumentListener的间接源的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个文档侦听器,它是间接源JTextArea(JTextArea.getDocument().addDocumentListener等.).

I have a document listener, and it's indirect source, JTextArea (JTextArea.getDocument().addDocumentListener etc..).

我需要我的侦听器访问JTextArea,但没有引用.与动作和键侦听器中的event.getSource()类似.我知道侦听器的源是文档,而不是JTextArea本身,但是我需要获取它.

I need my listener to have access to JTextArea, but without referencing. Something similar to event.getSource() from action and key listeners... I'm aware that the source of the listener is the document, not JTextArea itself, but I need to get to it.

有什么建议吗?

推荐答案

文档是文本组件的模型,而Swing是为单个模型构建的,可以被多个视图使用.因此,据我所知,您的问题的答案是否定的,这不能直接完成,因为许多文本组件可以使用同一文档.

A Document is the model of a text component, and Swing is built for a single model to be able to be used by many views. So the answer to your question as far as I know of is no, this can't be done directly, since many text components can use the same Document.

您声明:

它应删除所有多余的文本(也必须考虑复制/粘贴),并弹出一个对话框,通知用户限制.我仍然不确定如何实现(记住复制/粘贴,没有复制就可以轻松完成),因此,如果您有想法,但是无论如何我都需要解决这个论点问题...

It should remove all the excess text(copy/paste have to be taken into consideration too) and a dialog should popout informing user of the limitation. I am still unsure how to achieve that(having copy/paste in mind, without it it can be done easy), so if you have ideas shoot, but I'll need this argument issue solved anyway...

我想知道您是否需要对JTextArea的输入进行大量控制,也许您不应该使用JTextArea.相反,也许您应该使用一个JList并完全控制如何从该组件添加和删除行.

I wonder if you need that much control over input into a JTextArea, perhaps you shouldn't be using a JTextArea. Instead perhaps you should us a JList and completely control how lines are added and removed from this component.

这篇关于获取DocumentListener的间接源的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆