且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何从JTextPane删除组件

更新时间:2023-12-05 18:28:46

您将其视为特定位置的字符:

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]-一些文本

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

,并且您要删除第二个和第三个组件:

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

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

请参见文档