需要带有缩进第一行的 JTextArea (或类似的)
如何扩展 JTextArea 以缩进第一行?我想在文本区域的左上角区域显示一些不可编辑的东西(例如一些图标)。这些项目将是一行文本的高度,因此如果 JTextArea 将第一行的部分内容留空,这些项目可以放置在那里。该字段必须是可编辑的并且是多行的。
我花了几天时间查看文本类和 UI 类的层次结构。我对这个架构有一个大致的了解 - 使用 Document 来存储文本,DefaultTextUI 进行绘画和显示。跟踪插入符等。然而,深入研究角色定位代码只会变得越来越混乱。
我想我可以从头开始,扩展组件,但这似乎是错误的方法。有人有足够的信心以“正确”的方式提供帮助吗?如果我们关闭论坛,我可能愿意补偿。
How can I extend JTextArea to indent the first line? I would like to display some non-editable things in the upperleft corner area of the text area (e.g. some icons). These items would be the height of one line of text, so if JTextArea were to leave part of the first line blank, these items could be layed out there. The field must be editable and multiline.
I've spent a few days looking through the hierarchy of text classes and UI classes. I have a general understanding of this architecture - uses Document to store the text, the DefaultTextUI does the painting & tracks the caret and so on. It just gets messier and messier, though, to dig down into the character positioning code.
I think I could start from scratch, extending Component, but this seems like the wrong approach. Anyone feel confident enough to help with the "right" way? I might be willing to compensate if we take off the forum.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
你不需要扩展任何东西。查看
JEditorPane
类。它能够显示文本、图像等。You don't need to extend anything. Have a look at the
JEditorPane
class. It is capable of displaying text, images etc.