how to remove component from JTextPane

人盡茶涼 提交于 2019-12-13 07:29:59

问题


OK. Inserting a component programatically is obvious: myJTextPane.insertComponent.

Accessing components was a little trickier, but I use something like: myJTextPane.getComponents().getComponents()[0]. (1)

But how do I remove a component programatically from myJTextPane?

(1) I am actually programming in Clojure, so the syntax may not be 100%.


回答1:


You treat it as a character at a specific position:

myJTextPane.getDocument().remove(int offs, int len)

For example if you have a text pane with components in this order:

[Component1] - [Component2] - [Component3] - some text

and you want to remove 2nd and 3rd components:

myJTextPane.getDocument().remove(1, 2)

See documentation



来源:https://stackoverflow.com/questions/12859751/how-to-remove-component-from-jtextpane

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