https://www.weweweb.net/wiki/index.php?title=JAVA_PROGRAMMING_SWING_TEXT&feed=atom&action=history
JAVA PROGRAMMING SWING TEXT - Revision history
2024-03-28T15:13:13Z
Revision history for this page on the wiki
MediaWiki 1.35.5
https://www.weweweb.net/wiki/index.php?title=JAVA_PROGRAMMING_SWING_TEXT&diff=129&oldid=prev
Willy: Created page with "StyledDocument insert text: StyleContext context = new StyleContext(); StyledDocument document = new DefaultStyledDocument(context); Style style = context.getSt..."
2022-01-27T12:58:41Z
<p>Created page with "StyledDocument insert text: StyleContext context = new StyleContext(); StyledDocument document = new DefaultStyledDocument(context); Style style = context.getSt..."</p>
<p><b>New page</b></p><div>StyledDocument insert text:<br />
<br />
StyleContext context = new StyleContext();<br />
StyledDocument document = new DefaultStyledDocument(context);<br />
<br />
Style style = context.getStyle(StyleContext.DEFAULT_STYLE);<br />
StyleConstants.setAlignment(style, StyleConstants.ALIGN_RIGHT);<br />
StyleConstants.setFontSize(style, 14);<br />
StyleConstants.setSpaceAbove(style, 4);<br />
StyleConstants.setSpaceBelow(style, 4);<br />
<br />
// Insert content<br />
try {<br />
document.insertString(document.getLength(), message, style);<br />
} catch (BadLocationException badLocationException) {<br />
System.err.println("Oops");<br />
}<br />
<br />
SimpleAttributeSet attributes = new SimpleAttributeSet();<br />
StyleConstants.setBold(attributes, true);<br />
StyleConstants.setItalic(attributes, true);<br />
<br />
// Insert content<br />
try {<br />
document.insertString(document.getLength(), "Hello Java",<br />
attributes);<br />
} catch (BadLocationException badLocationException) {<br />
System.err.println("Oops");<br />
}</div>
Willy