Difference between revisions of "JAVA PROGRAMMING SWING TEXT"
From WeWeWeb Wiki
Jump to navigationJump to search (Created page with "StyledDocument insert text: StyleContext context = new StyleContext(); StyledDocument document = new DefaultStyledDocument(context); Style style = context.getSt...") |
(No difference)
|
Latest revision as of 20:58, 27 January 2022
StyledDocument insert text:
StyleContext context = new StyleContext(); StyledDocument document = new DefaultStyledDocument(context); Style style = context.getStyle(StyleContext.DEFAULT_STYLE); StyleConstants.setAlignment(style, StyleConstants.ALIGN_RIGHT); StyleConstants.setFontSize(style, 14); StyleConstants.setSpaceAbove(style, 4); StyleConstants.setSpaceBelow(style, 4); // Insert content try { document.insertString(document.getLength(), message, style); } catch (BadLocationException badLocationException) { System.err.println("Oops"); } SimpleAttributeSet attributes = new SimpleAttributeSet(); StyleConstants.setBold(attributes, true); StyleConstants.setItalic(attributes, true); // Insert content try { document.insertString(document.getLength(), "Hello Java", attributes); } catch (BadLocationException badLocationException) { System.err.println("Oops"); }