JTextPane に JLabel を使用してテキストを追加した後、JTextPane 内のすべての JLabel のテキストを変更する必要があります。どうすればいいですか?
...
JTextPane pane = new JTextPane();
HTMLEditorKit kit = new CompEditorKit();
HTMLDocument doc = new HTMLDocument();
pane.setEditable(false);
pane.setContentType("text/html");
pane.setEditorKit(kit);
pane.setDocument(doc);
...
kit.insertHTML(doc, doc.getLength(), "Test<object align=\"left\" classid=\"javax.swing.JLabel\"><param name=\"text\" value=\"22\"></object>Test", 0, 0, null);
EditLabels(doc);
...
public void EditLabels(Document doc) {
if (doc instanceof HTMLDocument) {
Element elem = doc.getDefaultRootElement();
ElementIterator iterator = new ElementIterator(elem);
while ((elem = iterator.next()) != null) {
AttributeSet attrs = elem.getAttributes();
Object elementName = attrs.getAttribute(AbstractDocument.ElementNameAttribute);
Object o = (elementName != null) ? null : attrs.getAttribute(StyleConstants.NameAttribute);
if (o instanceof HTML.Tag) {
if ((HTML.Tag) o == HTML.Tag.OBJECT) {
View view = new CompView(elem);
//View view = (View)super.create(elem); //ERROR
//if (view instanceof JLabel)
//{
// ((JLabel) view).setText("NM");
// JLabel label = (JLabel)view;
//}
}
}
}
}
}
例えば
View view = new CompView(elem);
((JLabel) view).setText("NM");
error: inconvertible types
required: JLabel
found: View
View view = (View)super.create(elem);
error: cannot find symbol
symbol: method create(Element)