Skip to main content

Changing the attributes of a TABLE element does not update the view

1 reply [Last post]
Joined: 2006-02-17

I'm trying to set the alignment of a TABLE element relative to an HTML page. My JEditorPane contains a subclassed HTMLDocument.

I had to override HTMLDocument.setParagraphAttributes() like so, to prevent it from changing the attributes of the TD elements as well.

<br />
	public void setAttributes(Element e, AttributeSet a, boolean replace)<br />
	{<br />
		try {<br />
			writeLock();<br />
			int offset = e.getStartOffset();<br />
			int length = e.getEndOffset() - offset;<br />
			AttributeSet copy = a.copyAttributes();<br />
			MutableAttributeSet attr = (MutableAttributeSet)e.getAttributes();<br />
			DefaultDocumentEvent changes = new DefaultDocumentEvent(offset, length,<br />
<p>			changes.addEdit(new AttributeUndoableEdit(e, copy, replace));<br />
			if (replace)<br />
				attr.removeAttributes(a);<br />
			attr.addAttributes(a);<br />
			changes.end();<br />
			fireChangedUpdate(changes);<br />
			fireUndoableEditUpdate(new UndoableEditEvent(this, changes));<br />
			dump();<br />
		} finally {<br />
			writeUnlock();<br />
		}<br />
	}<br />

After this code executes, a dump() shows that the attributes of the TABLE element change, but the view doesn't get updated. So if I change the ALIGN attribute (or any attribute for that matter), the table doesn't move. Changing the ALIGN attribute of a block tag such as H1 or P works as expected - the text inside the tag gets correctly aligned.

What more do I have to do? Any ideas are appreciated.

Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.

I've had similar problem with event generation. Try to fire INSERT event instead of CHANGE.

You can try to add an
AbstractUndoableEdit() with empty arrays of Inserted and removed elements.