Terje Dahl
Terje Dahl

Reputation: 982

how to remove component from JTextPane

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%.

Upvotes: 1

Views: 893

Answers (1)

Rempelos
Rempelos

Reputation: 1220

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

Upvotes: 4

Related Questions