SWING 中的代码/文本折叠
我正在寻找一种方法来为 swing JTextArea 或 JTextPane 提供“文本折叠”功能。
更具体地说,我想在文本组件中添加一个数据块,并且希望该组件仅显示一些标题行。然后用户可以通过单击某个图标来展开该块。这就像大多数 IDE 中的代码折叠功能一样。
经过一番彻底的搜索后,我发现了->一些示例代码<-,但是所使用的机制这对我来说很晦涩,当我尝试从文档中删除文本时,它停止工作。
也许使用 XML 作为输入可能是一个线索?
I'm looking for a way to provide 'text folding' capabilities to a swing JTextArea or JTextPane
More specifically, I want to add a block of data in a text component and I want the component to display only some header line. Then the user can unfold the block by clicking some icon. This is just like the code folding feature in most IDE.
I've found ->some sample code<- after some thorough search, but the mechanisms used here are quite obscure to me and it stops working when I try to remove text from the document.
Maybe using XML as input could be a lead ?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我首先查看 NetBeans API: http://bits.netbeans.org/dev/javadoc/org-netbeans-modules-editor-fold/overview-summary.html
如果您自己执行此操作,则需要提供 < code>Document 实现,使
JTextComponent
认为正在添加或删除片段,然后附加告诉文档自行更新的单击事件。很多工作。从视觉上看,使用 JEditorPane 可能会更好,但这可能需要更多工作。
I would start by looking at the NetBeans API: http://bits.netbeans.org/dev/javadoc/org-netbeans-modules-editor-fold/overview-summary.html
If you were to do it yourself, you'd need to provide a
Document
implementation that makes theJTextComponent
think that pieces are being added or removed, then attach click events that tell the document to update itself. A lot of work.Visually, it may also be better to use
JEditorPane
, but that's probably more work.