AttributeSet aset = sc.addAttribute(SimpleAttributeSet.EMPTY, StyleConstants.Foreground, c); aset = sc.addAttribute(aset, StyleConstants.FontFamily, "Lucida Console"); aset = sc.addAttribute(aset, StyleConstants.Alignment, StyleConstants.ALIGN_JUSTIFIED);
final AttributeSet attr = cont.addAttribute(cont.getEmptySet(), StyleConstants.Foreground, Color.RED); final AttributeSet attrBlack = cont.addAttribute(cont.getEmptySet(), StyleConstants.Foreground, Color.BLACK); DefaultStyledDocument doc = new DefaultStyledDocument() { public void insertString (int offset, String str, AttributeSet a) throws BadLocationException {
import javax.swing.text.AttributeSet; import javax.swing.text.SimpleAttributeSet; import javax.swing.text.StyleConstants; import javax.swing.text.StyleContext; private void appendToTextPane(String name, Color c, String f) { StyleContext sc = StyleContext.getDefaultStyleContext(); AttributeSet aset = sc.addAttribute(SimpleAttributeSet.EMPTY, StyleConstants.Foreground, c); aset = sc.addAttribute(aset, StyleConstants.FontFamily, f); int len = Client.nPane.getDocument().getLength(); textPane.setCaretPosition(len); textPane.setCharacterAttributes(aset, true); textPane.replaceSelection(name); }
/** * Appends text to this console. * * @param text The text to appendInfo */ public void appendInfo(String text) { AttributeSet aset = styleContext.addAttribute(SimpleAttributeSet.EMPTY, StyleConstants.Foreground, Color.WHITE); aset = styleContext.addAttribute(aset, StyleConstants.Alignment, StyleConstants.ALIGN_LEFT); append(text, aset); }
public void appendError(String text) { AttributeSet aset = styleContext.addAttribute(SimpleAttributeSet.EMPTY, StyleConstants.Foreground, Color.RED); aset = styleContext.addAttribute(aset, StyleConstants.Alignment, StyleConstants.ALIGN_LEFT); append(text, aset); }
private void changeAttribute(Color color) { lastColor = color; StyleContext sc = StyleContext.getDefaultStyleContext(); aset = sc.addAttribute(SimpleAttributeSet.EMPTY, StyleConstants.Foreground, color); } /**
private void changeAttribute(Color color) { lastColor = color; StyleContext sc = StyleContext.getDefaultStyleContext(); aset = sc.addAttribute(SimpleAttributeSet.EMPTY, StyleConstants.Foreground, color); } /**
private void appendToPane(JTextPane tp, String msg, Color c) { StyleContext sc = StyleContext.getDefaultStyleContext(); AttributeSet aset = sc.addAttribute(SimpleAttributeSet.EMPTY, StyleConstants.Foreground, c); aset = sc.addAttribute(aset, StyleConstants.FontFamily, "Lucida Console"); aset = sc.addAttribute(aset, StyleConstants.Alignment, StyleConstants.ALIGN_JUSTIFIED); int len = tp.getDocument().getLength(); tp.setCaretPosition(len); tp.setCharacterAttributes(aset, false); tp.replaceSelection(msg); }
/** * Appends a string to the JTextPane, with style attributes applied. * * @param s the String to be appended * @param attr a Map of attributes used to style the string */ public void append(String s, Map<Object, Object> attr) { StyleContext sc = StyleContext.getDefaultStyleContext(); AttributeSet aset = SimpleAttributeSet.EMPTY; // some default attributes if (attr == null) { attr = new HashMap<>(); attr.put(StyleConstants.Foreground, Color.BLACK); attr.put(StyleConstants.Background, Color.WHITE); } // add attributes for (Object key : attr.keySet()) { aset = sc.addAttribute(aset, key, attr.get(key)); } int len = getDocument().getLength(); setCaretPosition(len); setCharacterAttributes(aset, true); replaceSelection(s); }
public void appendText(String s) { StyleContext sc = StyleContext.getDefaultStyleContext(); AttributeSet aset = sc.addAttribute(SimpleAttributeSet.EMPTY, StyleConstants.Foreground, Color.BLACK); textField.setCharacterAttributes(aset, false); textField.replaceSelection(s); int len = doc.getLength(); textField.setCaretPosition(len); }
public void appendError(String s) { StyleContext sc = StyleContext.getDefaultStyleContext(); AttributeSet aset = sc.addAttribute(SimpleAttributeSet.EMPTY, StyleConstants.Foreground, Color.RED); textField.setCharacterAttributes(aset, false); textField.replaceSelection(s); int len = doc.getLength(); textField.setCaretPosition(len); }
this.attributeSet = styleContext.addAttribute(styleContext.getEmptySet(), StyleConstants.Foreground, color);
AttributeSet aset = sc.addAttribute(SimpleAttributeSet.EMPTY, StyleConstants.Foreground, c); aset = sc.addAttribute(aset, StyleConstants.Background, bColor); aset = sc.addAttribute(aset, StyleConstants.FontFamily, "Lucida Console"); aset = sc.addAttribute(aset, StyleConstants.Alignment, StyleConstants.ALIGN_JUSTIFIED);
AttributeSet aset = sc.addAttribute(SimpleAttributeSet.EMPTY, StyleConstants.Foreground, c); aset = sc.addAttribute(aset, StyleConstants.FontFamily, "Lucida Console"); aset = sc.addAttribute(aset, StyleConstants.Alignment, StyleConstants.ALIGN_JUSTIFIED);
private void print(String s, TextColor c) { StyleContext sc = StyleContext.getDefaultStyleContext(); AttributeSet color = sc.addAttribute(SimpleAttributeSet.EMPTY, StyleConstants.Foreground, c.getColor()); int len = textPane.getDocument().getLength(); textPane.setCaretPosition(len); textPane.setCharacterAttributes(color, false); textPane.replaceSelection(s); }
AttributeSet aset = sc.addAttribute(SimpleAttributeSet.EMPTY, StyleConstants.Foreground, f); aset = sc.addAttribute(aset, StyleConstants.Background, b); aset = sc.addAttribute(aset, StyleConstants.FontFamily, "Lucida Console"); aset = sc.addAttribute(aset, StyleConstants.Alignment, StyleConstants.ALIGN_JUSTIFIED);
AttributeSet aset = sc.addAttribute(SimpleAttributeSet.EMPTY, StyleConstants.Foreground, c); aset = sc.addAttribute(aset, StyleConstants.FontFamily, "Lucida Console"); aset = sc.addAttribute(aset, StyleConstants.Alignment, StyleConstants.ALIGN_JUSTIFIED);
Color color = getColor(s); StyleContext style = StyleContext.getDefaultStyleContext(); AttributeSet attrs = style.addAttribute(SimpleAttributeSet.EMPTY,StyleConstants.Foreground, color); pane.setCaretPosition(pane.getDocument().getLength()); pane.setCharacterAttributes(attrs , false);
AttributeSet aset = sc.addAttribute(SimpleAttributeSet.EMPTY, StyleConstants.TabSet, tabset); pane.setParagraphAttributes(aset, false);
AttributeSet aset = sc.addAttribute(SimpleAttributeSet.EMPTY, StyleConstants.Foreground, Color.BLUE); aset = sc.addAttribute(aset, StyleConstants.FontFamily, "Lucida Console");