DefaultStyledDocument document = new DefaultStyledDocument(); JTextPane textpane = new JTextPane(document); StyleContext context = new StyleContext(); // build a style Style style = context.addStyle("test", null); // set some style properties StyleConstants.setForeground(style, Color.BLUE); // add some data to the document document.insertString(0, "", style);
public GuardedDocument(Class kitClass) { this(kitClass, true, new StyleContext()); }
public GuardedDocument(Class kitClass) { this(kitClass, true, new StyleContext()); }
public DefaultStyledDocument() { this(new GapContent(BUFFER_SIZE_DEFAULT), new StyleContext()); }
new HTMLDocument(new GapContent(/*whatever works for you*/), new StyleContext())
private static final RTFEditorKit RTF_KIT = new RTFEditorKit(); (...) _txtHelp.setContentType("text/rtf"); final InputStream inputStream = new FileInputStream(_helpFile); final DefaultStyledDocument styledDocument = new DefaultStyledDocument(new StyleContext()); RTF_KIT.read(inputStream, styledDocument, 0); _txtHelp.setDocument(styledDocument);
String text = jTextPane.getSelectedText(); int cursorPosition = jTextPane.getCaretPosition(); StyleContext context = new StyleContext(); Style style; jTextPane.replaceSelection(""); style = context.addStyle("mystyle", null); style.addAttribute(StyleConstants.FontSize, new Integer(16)); jTextPane.getStyledDocument().insertString(cursorPosition - text.length(), text, style);
Image image = ImageIO.read(new File("myImage.jpg")); StyleContext context = new StyleContext(); StyledDocument document = new DefaultStyledDocument(context); Style labelStyle = context.getStyle(StyleContext.DEFAULT_STYLE); Icon icon = new ImageIcon(image); JLabel label = new JLabel(icon); StyleConstants.setComponent(labelStyle, label); document.insertString(document.getLength(), "Ignored", labelStyle); JTextPane textPane = new JTextPane(document);
StyleContext context = new StyleContext(); StyledDocument document = new DefaultStyledDocument(context); Style style = context.getStyle(StyleContext.DEFAULT_STYLE); StyleConstants.setAlignment(style, StyleConstants.ALIGN_CENTER); JTextPane output = new JTextPane(document); output.setFont(font);
StyleContext context = new StyleContext(); Style style = context.addStyle("mystyle", null); style.addAttribute(StyleConstants.FontSize, new Integer(16));; jTextPane.setCharacterAttributes(style , true);
Document doc = yourEditorPane.getDocument(); StyleContext sc = new StyleContext(); Style style = sc.addStyle("yourStyle", null); Font font = new Font("Arial", Font.BOLD, 18); StyleConstants.setForeground(style, Color.RED); StyleConstants.setFontFamily(style, font.getFamily()); StyleConstants.setBold(style, true); doc.insertString(doc.getLength(), "Hello World!", style);
@Override public Collection<MessageFragmentStyle> colorize(String message) { Collection<MessageFragmentStyle> list = new ArrayList<>(); StyleContext styleContext = new StyleContext(); for (int i = 0; i <= groupCount; i++) { if (StyleProperties.isStyleForGroupDeclared(i, configuration)) { Style style = StyleProperties.getStyle(theme.themeType(), styleContext, configuration, "propStyle" + getName(), i); list.addAll(MessageColorizerUtils.colorizeRegex(style, message, pattern, i)); } } return list; }
DefaultStyledDocument doc = new DefaultStyledDocument(); StyleContext sc = new StyleContext(); Style style = sc.addStyle("strikethru", null); StyleConstants.setStrikeThrough (style,true); doc.insertString (0, "Hello ", null); doc.insertString (6, "strike through ", style); JTextPane pane = new JTextPane(doc);
DefaultStyledDocument document = new DefaultStyledDocument(); JTextPane textpane = new JTextPane(document); StyleContext context = new StyleContext(); // build a style Style style = context.addStyle("test", null); // set some style color StyleConstants.setForeground(style, Color.RED); // add some data to the document document.insertString(0, "", style); OR JTextPane pane = new JTextPane(); SimpleAttributeSet set = new SimpleAttributeSet(); StyleConstants.setForeground(set, Color.red); Document doc = pane.getStyledDocument(); doc.insertString(doc.getLength(), "Kleine ", set);
/** * Constructs an XMLEditorKit with view factory and Context, but with line * wrapping turned off. */ public XMLEditorKit() { context = new StyleContext(); setStyle(ELEMENT_NAME, new Color(136, 18, 128), Font.PLAIN); setStyle(ELEMENT_VALUE, Color.black, Font.PLAIN); setStyle(ELEMENT_PREFIX, new Color(136, 18, 128), Font.PLAIN); setStyle(ATTRIBUTE_NAME, new Color(153, 69, 0), Font.PLAIN); setStyle(ATTRIBUTE_VALUE, new Color(26, 26, 166), Font.PLAIN); setStyle(ATTRIBUTE_PREFIX, new Color(153, 69, 0), Font.PLAIN); setStyle(NAMESPACE_NAME, new Color(128, 128, 0), Font.PLAIN); setStyle(NAMESPACE_VALUE, new Color(63, 95, 191), Font.PLAIN); setStyle(NAMESPACE_PREFIX, new Color(128, 128, 0), Font.PLAIN); setStyle(ENTITY, new Color(102, 102, 102), Font.PLAIN); setStyle(CDATA, new Color(127, 159, 191), Font.PLAIN); setStyle(COMMENT, new Color(63, 127, 95), Font.PLAIN); setStyle(SPECIAL, new Color(102, 102, 102), Font.PLAIN); factory = new XMLViewFactory(); }
@Override public Collection<MessageFragmentStyle> colorize(String textToColorize) { Collection<MessageFragmentStyle> list = new ArrayList<>(); if (StringUtils.isEmpty(searchString)) { return list; } StyleContext sc = new StyleContext(); Style searchStyle = sc.addStyle("searchResult", sc.getStyle(StyleContext.DEFAULT_STYLE)); final Color color = theme.getColor(ThemeKey.SEARCH_RESULT); StyleConstants.setBackground(searchStyle, color); if (searchMode.equals(SearchMode.STRING_CONTAINS)) { list.addAll(colorizeString(textToColorize, searchStyle, searchString)); } else if (searchMode.equals(SearchMode.REGEX)) { list.addAll(MessageColorizerUtils.colorizeRegex(searchStyle, textToColorize, Pattern.compile(searchString, Pattern.CASE_INSENSITIVE), 0)); } for (MessageFragmentStyle style : list) { style.setSearchResult(true); } return list; }
private void createStyles() { StyleContext context = new StyleContext(); VALID = context.getStyle(StyleContext.DEFAULT_STYLE); StyleConstants.setFontFamily(VALID, "Arial"); StyleConstants.setFontSize(VALID, 12); StyleConstants.setForeground(VALID, Color.GREEN.darker()); StyleContext context1 = new StyleContext(); CRITICAL_ERROR = context1.getStyle(StyleContext.DEFAULT_STYLE); StyleConstants.setFontFamily(CRITICAL_ERROR, "Arial"); StyleConstants.setFontSize(CRITICAL_ERROR, 12); StyleConstants.setForeground(CRITICAL_ERROR, Color.RED); StyleContext context2 = new StyleContext(); NONCRITICAL_ERROR = context2.getStyle(StyleContext.DEFAULT_STYLE); StyleConstants.setFontFamily(NONCRITICAL_ERROR, "Arial"); StyleConstants.setFontSize(NONCRITICAL_ERROR, 12); StyleConstants.setForeground(NONCRITICAL_ERROR, Color.BLACK); StyleContext context3 = new StyleContext(); NORMAL = context3.getStyle(StyleContext.DEFAULT_STYLE); StyleConstants.setFontFamily(NONCRITICAL_ERROR, "Arial"); StyleConstants.setFontSize(NONCRITICAL_ERROR, 11); StyleConstants.setForeground(NONCRITICAL_ERROR, Color.BLACK); }
/** * Creates new form QueryInterfacePanel */ public QueryInterfacePanel(OBDAModel apic, QueryController qc) { this.qc = qc; this.apic = apic; initComponents(); StyleContext style = new StyleContext(); styledDocument = new DefaultStyledDocument(style); queryTextPane.setDocument(styledDocument); queryTextPane.setBackground(Color.WHITE); queryTextPane.setCaretColor(Color.BLACK); queryTextPane.addKeyListener(new CTRLEnterKeyListener()); }
private static StyleContext getDefaultStyleContext() { StyleContext result = new StyleContext(); Style defaultStyle = StyleContext.getDefaultStyleContext().getStyle( StyleContext.DEFAULT_STYLE ); Style baseStyle = result.addStyle( "base", defaultStyle ); Style regularStyle = result.addStyle( STYLE_REGULAR, baseStyle ); StyleConstants.setFontFamily( regularStyle, Font.MONOSPACED ); StyleConstants.setFontSize( regularStyle, 12 ); Style hyperStyle = result.addStyle( STYLE_HYPERLINK, regularStyle ); StyleConstants.setForeground( hyperStyle, COLOR_HYPER ); StyleConstants.setUnderline( hyperStyle, true ); Style titleStyle = result.addStyle( STYLE_TITLE, baseStyle ); StyleConstants.setFontFamily( titleStyle, Font.SANS_SERIF ); StyleConstants.setFontSize( titleStyle, 24 ); StyleConstants.setBold( titleStyle, true ); return result; } }
protected void initStyles() { styleContext = new StyleContext(); Style defaultStyle = styleContext.getStyle(StyleContext.DEFAULT_STYLE); StyleConstants.setFontFamily(defaultStyle, "courier"); styleStackTrace = styleContext.addStyle("stackTrace", defaultStyle); StyleConstants.setBackground(styleStackTrace, theme.getColor(ThemeKey.LOG_DETAILS_STACKTRACE_BACKGROUND)); StyleConstants.setForeground(styleStackTrace, theme.getColor(ThemeKey.LOG_DETAILS_STACKTRACE_FOREGROUND)); stylePackage = styleContext.addStyle("stylePackage", styleStackTrace); styleClass = styleContext.addStyle("styleClass", stylePackage); StyleConstants.setForeground(styleClass, theme.getColor(ThemeKey.LOG_DETAILS_STACKTRACE_CLASS)); StyleConstants.setBold(styleClass, true); styleMethod = styleContext.addStyle("styleMethod", styleStackTrace); StyleConstants.setForeground(styleMethod, theme.getColor(ThemeKey.LOG_DETAILS_STACKTRACE_METHOD)); StyleConstants.setItalic(styleMethod, true); StyleConstants.setBold(styleMethod, true); styleFile = styleContext.addStyle("styleFile", styleStackTrace); StyleConstants.setForeground(styleFile, theme.getColor(ThemeKey.LOG_DETAILS_STACKTRACE_FLE)); StyleConstants.setUnderline(styleFile, true); styleCodeComment = styleContext.addStyle("styleCodeComment", defaultStyle); StyleConstants.setForeground(styleCodeComment, theme.getColor(ThemeKey.LOG_DETAILS_STACKTRACE_COMMENT)); StyleConstants.setItalic(styleCodeComment, true); }