好的。以编程方式插入组件是显而易见的:myJTextPane.insertComponent
。
访问组件有点棘手,但我使用类似:myJTextPane.getComponents().getComponents()[0]
。 (1)
但是如何以编程方式从 myJTextPane 中删除组件?
(1) 我实际上是在 Clojure 中编程,所以语法可能不是 100%。
最佳答案
您将其视为特定位置的字符:
myJTextPane.getDocument().remove(int offs, int len)
例如,如果您有一个文本 Pane ,其组件按以下顺序排列:
[组件1] - [组件2] - [组件3] - 一些文本
并且您想要删除第二个和第三个组件:
myJTextPane.getDocument().remove(1, 2)
关于java - 如何从 JTextPane 中删除组件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12859751/