Article View: borland.public.jbuilder.java.swing
Article #12754Changing the Style of a HTML Document
From: Brett Walker
Date: Fri, 13 Nov 1998 00:00
Date: Fri, 13 Nov 1998 00:00
54 lines
2410 bytes
2410 bytes
Hi,
I am trying to change the style of a select of HTML. The following code:
HTMLDocument doc = (HTMLDocument) editorPane.getDocument();
MutableAttributeSet s = new SimpleAttributeSet();
s.addAttribute(StyleConstants.NameAttribute, HTML.Tag.B);
int start = editorPane.getSelectionStart();
int end = editorPane.getSelectionEnd();
doc.setCharacterAttributes(start,end,s,false);
gives
Exception occurred during event dispatching:
Can't build a b, LeafElement(b) 179,195
at
javax.swing.text.html.HTMLEditorKit$HTMLFactory.create(HTMLEditorKit.java:705)
at
javax.swing.text.ParagraphView.updateLogicalChildren(ParagraphView.java:825)
at javax.swing.text.ParagraphView.changedUpdate(ParagraphView.java:890)
at javax.swing.text.BoxView.changedUpdate(BoxView.java:502)
at javax.swing.text.BoxView.changedUpdate(BoxView.java:502)
at
javax.swing.plaf.basic.BasicTextUI$RootView.changedUpdate(BasicTextUI.java:1180)
at
javax.swing.plaf.basic.BasicTextUI$UpdateHandler.changedUpdate(BasicTextUI.java:1398)
at
javax.swing.text.AbstractDocument.fireChangedUpdate(AbstractDocument.java:184)
at
javax.swing.text.DefaultStyledDocument.setCharacterAttributes(DefaultStyledDocument.java:355)
at Wave.EditWindow$BoldAction.actionPerformed(EditWindow.java:578)
However the following code
HTMLDocument doc = (HTMLDocument) editorPane.getDocument();
MutableAttributeSet s = new SimpleAttributeSet();
// s.addAttribute(StyleConstants.NameAttribute, HTML.Tag.B);
StyleConstants.setBold(s, true);
int start = editorPane.getSelectionStart();
int end = editorPane.getSelectionEnd();
doc.setCharacterAttributes(start,end,s,false);
doesn't throw the exception, it adds an attribute of Bold that ins't
translated into HTML.
Thanks for any help or suggestions.
Cheers
Technical Details
Message-ID:
<364B7997.A0F37C98@ozemail.com.au>Path:
arc1-ca.pugleaf.net!unknown!not-for-mailShow Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 111d45,b92d240cfea8445,start X-Google-Attributes: gid111d45,public From: Brett Walker <walkb@ozemail.com.au> Subject: Changing the Style of a HTML Document Date: 1998/11/13 Message-ID: <364B7997.A0F37C98@ozemail.com.au> X-Deja-AN: 411271918 Content-Transfer-Encoding: 7bit X-Accept-Language: en Content-Type: text/plain; charset=us-ascii Organization: Another Netscape Collabra Server User Mime-Version: 1.0 Newsgroups: borland.public.jbuilder.java.swing