Difference between pages "PSP WALKTHROUGH" and "JAVA PROGRAMMING SWING TEXT"
From WeWeWeb Wiki
(Difference between pages)
Jump to navigationJump to search (Created page with "ACE COMBAT X") |
(Created page with "StyledDocument insert text: StyleContext context = new StyleContext(); StyledDocument document = new DefaultStyledDocument(context); Style style = context.getSt...") |
||
Line 1: | Line 1: | ||
− | + | 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"); | ||
+ | } |
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"); }