tp.setCharacterAttributes(aset, false); tp.replaceSelection(msg);
private void setStyle(AttributeSet attributes, boolean overWrite) { text.setCharacterAttributes(attributes, overWrite); }
Style s; //your style JTextPane textPane; //your textpane textPane.setCharacterAttributes( s, false );
public WarnaText(JTextPane source) throws BadLocationException { source.setForeground(Color.BLACK); Matcher komen=Pattern.compile("(/\\*([^\\*]|(\\*(?!/))+)*+\\*+/)|(\\/\\/.+)").matcher(source.getText()); while(komen.find()) { StyleContext sc = StyleContext.getDefaultStyleContext(); AttributeSet aset = sc.addAttribute(SimpleAttributeSet.EMPTY, StyleConstants.Foreground, Color.RED); aset = sc.addAttribute(aset, StyleConstants.FontFamily, "Concolas"); source.select(komen.start(),komen.end()); source.setCharacterAttributes(aset, false); } }
// This is in javax.swing.JTextPane; JTextPane tPane = new JTextPane(); /* Method to put text in this textPane with colour of your choice * For this you need these classes. * import javax.swing.text.AttributeSet; * import javax.swing.text.SimpleAttributeSet; * import javax.swing.text.StyleConstants; * import javax.swing.text.StyleContext; */ protected static void appendToPane(String msg, 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 = tPane.getDocument().getLength(); tPane.setCaretPosition(len); tPane.setCharacterAttributes(aset, false); tPane.replaceSelection(msg); }
private void append(String text, AttributeSet attributes) { if (this.isVisible()) { int len = textArea.getDocument().getLength(); textArea.setCaretPosition(len); textArea.setCharacterAttributes(attributes, false); textArea.replaceSelection("\n" + text); textArea.repaint(); } else { buffer.append(text); } } }
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); }
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); }
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); }
pane.setCharacterAttributes(set, true); pane.setText("Eine ");
private void maintainForegroundColor() { // Ensure text typed into the console uses the foreground color. If we don't set it here, the // editor sometimes reuses a color from wherever the user may have moved the cursor in the console // and pressed Enter. _outputPanel.getInputAttributes(); SimpleAttributeSet sas = new SimpleAttributeSet(); StyleConstants.setForeground( sas, _outputPanel.getForeground() ); _outputPanel.setCharacterAttributes( sas, false ); } }
AttributeSet attrs = style.addAttribute(SimpleAttributeSet.EMPTY,StyleConstants.Foreground, color); pane.setCaretPosition(pane.getDocument().getLength()); pane.setCharacterAttributes(attrs , false); pane.replaceSelection(s+"\n");
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); }
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); }
int len = getText().length(); setCharacterAttributes(aset, false); setCharacterAttributes(aset, false);
tp.setCharacterAttributes(aset, false); tp.replaceSelection(msg);
tp.setCharacterAttributes(aset, false); tp.replaceSelection(msg);
sasText.addAttribute(p_, attribs); if (textLength > 0) parentTextPane.select(caretOffset, caretOffset + textLength); parentTextPane.setCharacterAttributes(sasText, true);