Java Code Examples for javax.swing.text.StyleConstants#setBold()
The following examples show how to use
javax.swing.text.StyleConstants#setBold() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: AboutDialog.java From Spade with GNU General Public License v3.0 | 6 votes |
public static void addStylesToDocument(StyledDocument doc) { //Initialize some styles. Style def = StyleContext.getDefaultStyleContext().getStyle(StyleContext.DEFAULT_STYLE); Style regular = doc.addStyle("regular", def); StyleConstants.setFontFamily(def, "SansSerif"); Style s = doc.addStyle("italic", regular); StyleConstants.setItalic(s, true); s = doc.addStyle("bold", regular); StyleConstants.setBold(s, true); s = doc.addStyle("small", regular); StyleConstants.setFontSize(s, 10); s = doc.addStyle("large", regular); StyleConstants.setFontSize(s, 16); StyleConstants.setBold(s, true); }
Example 2
Source File: JTerm.java From MobyDroid with Apache License 2.0 | 6 votes |
public JTerm(JTextPane jTextPane, JTermInputProcessor process, Color background, Color text, Font font) { super(); jTermTextPane = jTextPane; processor = process; jTermDoc = new JTermDocument(); jTermTextPane.setDocument(jTermDoc); jTermTextPane.setBackground(background); jTermTextPane.setCaretColor(text); jTermTextPane.addCaretListener(jTermDoc); jTermDoc.setCaret(jTermTextPane.getCaret()); defaultStyle = jTermTextPane.getInputAttributes(); StyleConstants.setFontFamily(defaultStyle, font.getFamily()); StyleConstants.setFontSize(defaultStyle, font.getSize()); StyleConstants.setItalic(defaultStyle, (font.getStyle() & Font.ITALIC) != 0); StyleConstants.setBold(defaultStyle, (font.getStyle() & Font.BOLD) != 0); StyleConstants.setForeground(defaultStyle, text); jTermDoc.setCharacterAttributes(0, jTermDoc.getLength() + 1, defaultStyle, false); jTermTextPane.addKeyListener(new JTermKeyListener()); //catch tabs, enters, and up/down arrows for autocomplete and input processing jTermTextPane.addMouseListener(new JTermMouseListener()); }
Example 3
Source File: ConsoleSupport.java From groovy with Apache License 2.0 | 6 votes |
protected void addStylesToDocument(JTextPane outputArea) { StyledDocument doc = outputArea.getStyledDocument(); Style def = StyleContext.getDefaultStyleContext().getStyle(StyleContext.DEFAULT_STYLE); Style regular = doc.addStyle("regular", def); StyleConstants.setFontFamily(def, "Monospaced"); promptStyle = doc.addStyle("prompt", regular); StyleConstants.setForeground(promptStyle, Color.BLUE); commandStyle = doc.addStyle("command", regular); StyleConstants.setForeground(commandStyle, Color.MAGENTA); outputStyle = doc.addStyle("output", regular); StyleConstants.setBold(outputStyle, true); }
Example 4
Source File: LogRecordEntry.java From rapidminer-studio with GNU Affero General Public License v3.0 | 6 votes |
/** * Creates a new {@link LogRecordEntry} which automatically formats the given {@link LogRecord} * with the RapidMiner Studio log styling and default logging format. * * @param logRecord */ public LogRecordEntry(LogRecord logRecord) { logLevel = logRecord.getLevel(); initialString = logRecord.getMessage(); simpleAttributeSet = new SimpleAttributeSet(); if (logRecord.getLevel().intValue() >= Level.SEVERE.intValue()) { StyleConstants.setForeground(simpleAttributeSet, COLOR_ERROR); StyleConstants.setBold(simpleAttributeSet, true); } else if (logRecord.getLevel().intValue() >= Level.WARNING.intValue()) { StyleConstants.setForeground(simpleAttributeSet, COLOR_WARNING); StyleConstants.setBold(simpleAttributeSet, true); } else if (logRecord.getLevel().intValue() >= Level.INFO.intValue()) { StyleConstants.setForeground(simpleAttributeSet, COLOR_INFO); StyleConstants.setBold(simpleAttributeSet, false); } else { StyleConstants.setForeground(simpleAttributeSet, COLOR_DEFAULT); StyleConstants.setBold(simpleAttributeSet, false); } formattedString = formatter.format(logRecord); }
Example 5
Source File: JConsole.java From COMP6237 with BSD 3-Clause "New" or "Revised" License | 6 votes |
private AttributeSet setStyle( String fontFamilyName, int size, Color color, boolean bold, boolean italic, boolean underline ) { final MutableAttributeSet attr = new SimpleAttributeSet(); if (color != null) StyleConstants.setForeground(attr, color); if (fontFamilyName != null) StyleConstants.setFontFamily(attr, fontFamilyName); if (size != -1) StyleConstants.setFontSize(attr, size); StyleConstants.setBold(attr, bold); StyleConstants.setItalic(attr, italic); StyleConstants.setUnderline(attr, underline); setStyle(attr); return getStyle(); }
Example 6
Source File: OurConsole.java From org.alloytools.alloy with Apache License 2.0 | 6 votes |
static MutableAttributeSet style(String fontName, int fontSize, boolean boldness, boolean italic, boolean strike, Color color, int leftIndent) { fontName = AlloyGraphics.matchBestFontName(fontName); MutableAttributeSet s = new SimpleAttributeSet(); StyleConstants.setFontFamily(s, fontName); StyleConstants.setFontSize(s, fontSize); StyleConstants.setLineSpacing(s, -0.2f); StyleConstants.setBold(s, boldness); StyleConstants.setItalic(s, italic); StyleConstants.setForeground(s, color); StyleConstants.setLeftIndent(s, leftIndent); StyleConstants.setStrikeThrough(s, strike); return s; }
Example 7
Source File: CommentPanel.java From triplea with GNU General Public License v3.0 | 5 votes |
private void init() { createComponents(); layoutComponents(); setupKeyMap(); StyleConstants.setBold(bold, true); StyleConstants.setItalic(italic, true); setSize(300, 200); loadHistory(); setupListeners(); }
Example 8
Source File: GUILog.java From PacketProxy with Apache License 2.0 | 5 votes |
public void appendErr(String s) { try { synchronized (thread_lock) { SimpleAttributeSet keyWord = new SimpleAttributeSet(); StyleConstants.setBackground(keyWord, new Color(240, 150, 150)); StyleConstants.setBold(keyWord, true); StyledDocument doc = text.getStyledDocument(); doc.insertString(doc.getLength() - 1, s + "\n", keyWord); } } catch (BadLocationException ex) { } }
Example 9
Source File: ChatMessagePanel.java From triplea with GNU General Public License v3.0 | 5 votes |
private void init() { createComponents(); layoutComponents(); StyleConstants.setBold(bold, true); StyleConstants.setItalic(italic, true); setSize(300, 200); }
Example 10
Source File: ConsoleCodeDocument.java From binnavi with Apache License 2.0 | 5 votes |
/** * Constructor. Sets up the styles and add the strings to be highlighted into the corresponding * vectors. */ public ConsoleCodeDocument() { super(false); putProperty(DefaultEditorKit.EndOfLineStringProperty, "\n"); StyleConstants.setForeground(pythonPromptAttr, Color.LIGHT_GRAY); StyleConstants.setBold(pythonPromptAttr, true); StyleConstants.setFontSize(pythonPromptAttr, 13); }
Example 11
Source File: TextPanelWithLinksDetector.java From ramus with GNU General Public License v3.0 | 5 votes |
private SimpleAttributeSet createLinkStyle() { SimpleAttributeSet linkStyle = new SimpleAttributeSet(); StyleConstants.setUnderline(linkStyle, true); StyleConstants.setBold(linkStyle, true); return linkStyle; }
Example 12
Source File: VersionPane.java From bigtable-sql with Apache License 2.0 | 5 votes |
/** * Renders the content. */ private void init() { String content = getContent(); setContentType("text/html"); StyledDocument doc = getStyledDocument(); SimpleAttributeSet s = new SimpleAttributeSet(); StyleConstants.setAlignment(s, StyleConstants.ALIGN_CENTER); StyleConstants.setBold(s, true); try { doc.setParagraphAttributes(0,content.length(), s, false); doc.insertString(0, content, s); if (_showWebsite) { String webContent = Version.getWebSite(); SimpleAttributeSet w = new SimpleAttributeSet(); StyleConstants.setAlignment(w, StyleConstants.ALIGN_CENTER); StyleConstants.setUnderline(w, true); SimpleAttributeSet hrefAttr = new SimpleAttributeSet(); hrefAttr.addAttribute(HTML.Attribute.HREF, Version.getWebSite()); w.addAttribute(HTML.Tag.A, hrefAttr); doc.setParagraphAttributes(content.length(),webContent.length(), w, false); doc.insertString(content.length(), webContent, w); if (Desktop.isDesktopSupported()){ addMouseListener(this); addMouseMotionListener(this); } } } catch (Exception e) { s_log.error("init: Unexpected exception "+e.getMessage()); } setOpaque(false); }
Example 13
Source File: ColorsManager.java From netbeans with Apache License 2.0 | 5 votes |
private static AttributeSet getUnusedFieldAttributes () { if (unusedFieldAttributeSet == null) { SimpleAttributeSet sas = new SimpleAttributeSet (); StyleConstants.setForeground (sas, new Color (115, 115, 115)); StyleConstants.setBold (sas, true); unusedFieldAttributeSet = sas; } return unusedFieldAttributeSet; }
Example 14
Source File: GroovyFilter.java From groovy with Apache License 2.0 | 4 votes |
private void init() { StyleContext styleContext = StyleContext.getDefaultStyleContext(); Style defaultStyle = styleContext.getStyle(StyleContext.DEFAULT_STYLE); Style comment = styleContext.addStyle(COMMENT, defaultStyle); StyleConstants.setForeground(comment, COMMENT_COLOR); StyleConstants.setItalic(comment, true); Style quotes = styleContext.addStyle(QUOTES, defaultStyle); StyleConstants.setForeground(quotes, Color.MAGENTA.darker().darker()); Style charQuotes = styleContext.addStyle(SINGLE_QUOTES, defaultStyle); StyleConstants.setForeground(charQuotes, Color.GREEN.darker().darker()); Style slashyQuotes = styleContext.addStyle(SLASHY_QUOTES, defaultStyle); StyleConstants.setForeground(slashyQuotes, Color.ORANGE.darker()); Style digit = styleContext.addStyle(DIGIT, defaultStyle); StyleConstants.setForeground(digit, Color.RED.darker()); Style operation = styleContext.addStyle(OPERATION, defaultStyle); StyleConstants.setBold(operation, true); Style ident = styleContext.addStyle(IDENT, defaultStyle); Style reservedWords = styleContext.addStyle(RESERVED_WORD, defaultStyle); StyleConstants.setBold(reservedWords, true); StyleConstants.setForeground(reservedWords, Color.BLUE.darker().darker()); Style leftParens = styleContext.addStyle(IDENT, defaultStyle); getRootNode().putStyle(SLASH_STAR_COMMENT, comment); getRootNode().putStyle(SLASH_SLASH_COMMENT, comment); getRootNode().putStyle(QUOTES, quotes); getRootNode().putStyle(SINGLE_QUOTES, charQuotes); getRootNode().putStyle(SLASHY_QUOTES, slashyQuotes); getRootNode().putStyle(new String[] { HEX_INTEGER_LITERAL, OCTAL_INTEGER_LITERAL, BINARY_INTEGER_LITERAL, DECIMAL_FLOATING_POINT_LITERAL, HEXADECIMAL_FLOATING_POINT_LITERAL, DECIMAL_INTEGER_LITERAL, }, digit); getRootNode().putStyle(OPERATION, operation); StructuredSyntaxDocumentFilter.LexerNode node = createLexerNode(); node.putStyle(RESERVED_WORDS, reservedWords); node.putStyle(LEFT_PARENS, leftParens); getRootNode().putChild(OPERATION, node); getRootNode().putStyle(IDENT, ident); node = createLexerNode(); node.putStyle(RESERVED_WORDS, reservedWords); getRootNode().putChild(IDENT, node); }
Example 15
Source File: KTextEdit.java From stendhal with GNU General Public License v2.0 | 4 votes |
/** * Initializes the basic styles. * * @param textPane * the active text component * @param mainTextSize size of regular text */ protected void initStylesForTextPane(final JTextPane textPane, int mainTextSize) { // ****** General style definitions for the text pane ****** Style regular = textPane.getStyle("regular"); if (regular == null) { final Style def = StyleContext.getDefaultStyleContext().getStyle( StyleContext.DEFAULT_STYLE); regular = textPane.addStyle("regular", def); StyleConstants.setFontFamily(def, "Dialog"); } StyleConstants.setFontSize(regular, mainTextSize); Style s = textPane.getStyle("normal"); if (s == null) { s = textPane.addStyle("normal", regular); StyleConstants.setBold(s, true); StyleConstants.setForeground(s, HEADER_COLOR); } s = textPane.getStyle("bold"); if (s == null) { s = textPane.addStyle("bold", regular); StyleConstants.setItalic(s, true); StyleConstants.setBold(s, true); StyleConstants.setForeground(s, Color.blue); } StyleConstants.setFontSize(regular, mainTextSize + 1); s = textPane.getStyle("header"); if (s == null) { s = textPane.addStyle("header", regular); StyleConstants.setItalic(s, true); StyleConstants.setForeground(s, HEADER_COLOR); } StyleConstants.setFontSize(s, mainTextSize); s = textPane.getStyle("timestamp"); if (s == null) { s = textPane.addStyle("timestamp", regular); StyleConstants.setItalic(s, true); StyleConstants.setForeground(s, HEADER_COLOR); } StyleConstants.setFontSize(s, mainTextSize - 1); //****** Styles used by the string formatter ****** StyleSet defaultAttributes = new StyleSet(StyleContext.getDefaultStyleContext(), regular); StyleSet attributes = defaultAttributes.copy(); attributes.setAttribute(StyleConstants.Italic, Boolean.TRUE); attributes.setAttribute(StyleConstants.Foreground, Color.blue); attributes.setAttribute("linkact", new LinkListener()); formatter.addStyle('#', attributes); attributes = defaultAttributes.copy(); attributes.setAttribute(StyleConstants.Underline, Boolean.TRUE); formatter.addStyle('ยง', attributes); }
Example 16
Source File: StyleProperties.java From otroslogviewer with Apache License 2.0 | 4 votes |
public static Style getStyle(Theme.Type themeType,StyleContext styleContext, DataConfiguration styleConfig, String styleName, int group) { Style style = styleContext.addStyle(styleName, styleContext.getStyle(StyleContext.DEFAULT_STYLE)); final String groupSuffix; if (group <= 0) { groupSuffix = ""; } else { groupSuffix = "." + group; } String fontFamily = styleConfig.getString(PROP_FONT_FAMILY + groupSuffix, ""); if (fontFamily.trim().length() > 0) { StyleConstants.setFontFamily(style, styleConfig.getString(PROP_FONT_FAMILY + groupSuffix)); } if (styleConfig.getString(PROP_FONT_SIZE + groupSuffix, "").trim().length() > 0) { StyleConstants.setFontSize(style, styleConfig.getInt(PROP_FONT_SIZE + groupSuffix)); } if (styleConfig.getString(PROP_FONT_BOLD + groupSuffix, "").trim().length() > 0) { StyleConstants.setBold(style, styleConfig.getBoolean(PROP_FONT_BOLD + groupSuffix)); } if (styleConfig.getString(PROP_FONT_ITALIC + groupSuffix, "").trim().length() > 0) { StyleConstants.setItalic(style, styleConfig.getBoolean(PROP_FONT_ITALIC + groupSuffix)); } if (styleConfig.getString(PROP_FONT_UNDERLINE + groupSuffix, "").trim().length() > 0) { StyleConstants.setUnderline(style, styleConfig.getBoolean(PROP_FONT_UNDERLINE + groupSuffix)); } String theme; if (themeType.equals(Theme.Type.Light)) { theme = "light"; } else { theme = "dark"; } if (styleConfig.getString(PROP_BACKGROUND + groupSuffix + "." + theme,"").trim().length() > 0) { StyleConstants.setBackground(style, styleConfig.getColor(PROP_BACKGROUND + groupSuffix + "." + theme, null)); } else if (styleConfig.getString(PROP_BACKGROUND + groupSuffix, "").trim().length() > 0) { StyleConstants.setBackground(style, styleConfig.getColor(PROP_BACKGROUND + groupSuffix)); } if (styleConfig.getString(PROP_FOREGROUND + groupSuffix + "." + theme,"").trim().length() > 0) { StyleConstants.setForeground(style, styleConfig.getColor(PROP_FOREGROUND + groupSuffix + "." + theme, null)); } else if (styleConfig.getString(PROP_FOREGROUND + groupSuffix, "").trim().length() > 0) { StyleConstants.setForeground(style, styleConfig.getColor(PROP_FOREGROUND + groupSuffix)); } return style; }
Example 17
Source File: CLIOutput.java From wildfly-core with GNU Lesser General Public License v2.1 | 4 votes |
public int postBoldAt(String text, int position) { SimpleAttributeSet attribs = new SimpleAttributeSet(); StyleConstants.setBold(attribs, true); return postAttributed(text, position, attribs); }
Example 18
Source File: ModelItem.java From netbeans with Apache License 2.0 | 4 votes |
private void updateFramesImpl(JEditorPane pane, boolean rawData) throws BadLocationException { Style defaultStyle = StyleContext.getDefaultStyleContext().getStyle(StyleContext.DEFAULT_STYLE); StyledDocument doc = (StyledDocument)pane.getDocument(); Style timingStyle = doc.addStyle("timing", defaultStyle); StyleConstants.setForeground(timingStyle, Color.lightGray); Style infoStyle = doc.addStyle("comment", defaultStyle); StyleConstants.setForeground(infoStyle, Color.darkGray); StyleConstants.setBold(infoStyle, true); SimpleDateFormat formatter = new SimpleDateFormat("HH:mm:ss:SSS"); pane.setText(""); StringBuilder sb = new StringBuilder(); int lastFrameType = -1; for (Network.WebSocketFrame f : wsRequest.getFrames()) { int opcode = f.getOpcode(); if (opcode == 0) { // "continuation frame" opcode = lastFrameType; } else { lastFrameType = opcode; } if (opcode == 1) { // "text frame" if (!rawData) { doc.insertString(doc.getLength(), formatter.format(f.getTimestamp()), timingStyle); doc.insertString(doc.getLength(), f.getDirection() == Network.Direction.SEND ? " SENT " : " RECV ", timingStyle); } doc.insertString(doc.getLength(), f.getPayload()+"\n", defaultStyle); } else if (opcode == 2) { // "binary frame" if (!rawData) { doc.insertString(doc.getLength(), formatter.format(f.getTimestamp()), timingStyle); doc.insertString(doc.getLength(), f.getDirection() == Network.Direction.SEND ? " SENT " : " RECV ", timingStyle); } // XXX: binary data??? doc.insertString(doc.getLength(), f.getPayload()+"\n", defaultStyle); } else if (opcode == 8) { // "close frame" if (!rawData) { doc.insertString(doc.getLength(), formatter.format(f.getTimestamp()), timingStyle); doc.insertString(doc.getLength(), f.getDirection() == Network.Direction.SEND ? " SENT " : " RECV ", timingStyle); } doc.insertString(doc.getLength(), "Frame closed\n", infoStyle); } } data = sb.toString(); pane.setCaretPosition(0); }
Example 19
Source File: ModelItem.java From netbeans with Apache License 2.0 | 4 votes |
private void updateTextPaneImpl(JTextPane pane) throws BadLocationException { Style defaultStyle = StyleContext.getDefaultStyleContext().getStyle(StyleContext.DEFAULT_STYLE); StyledDocument doc = pane.getStyledDocument(); Style boldStyle = doc.addStyle("bold", defaultStyle); StyleConstants.setBold(boldStyle, true); Style errorStyle = doc.addStyle("error", defaultStyle); StyleConstants.setBold(errorStyle, true); StyleConstants.setForeground(errorStyle, Color.red); Style paragraphStyle = doc.addStyle("paragraph", defaultStyle); StyleConstants.setFontSize(paragraphStyle, StyleConstants.getFontSize(paragraphStyle)+5); StyleConstants.setForeground(paragraphStyle, Color.gray); pane.setText(""); if (request != null) { doc.insertString(doc.getLength(), "Request URL: ", boldStyle); doc.insertString(doc.getLength(), (String)request.getRequest().get("url")+"\n", defaultStyle); doc.insertString(doc.getLength(), "Method: ", boldStyle); doc.insertString(doc.getLength(), (String)request.getRequest().get("method")+"\n", defaultStyle); JSONObject r = getResponseHeaders(); if (r != null) { int statusCode = request.getResponseCode(); doc.insertString(doc.getLength(), "Status: ", boldStyle); String status = (String)r.get("Status"); if (status == null) { status = statusCode == -1 ? "" : ""+statusCode + " " + request.getResponse().get("statusText"); } doc.insertString(doc.getLength(), status+"\n", statusCode >= 400 ? errorStyle : defaultStyle); Boolean fromCache = (Boolean)r.get("fromDiskCache"); if (Boolean.TRUE.equals(fromCache)) { doc.insertString(doc.getLength(), "From Disk Cache: ", boldStyle); doc.insertString(doc.getLength(), "yes\n", defaultStyle); } } else if (request.isFailed()) { doc.insertString(doc.getLength(), "Status: ", boldStyle); doc.insertString(doc.getLength(), "Request was cancelled.\n", errorStyle); } } else { doc.insertString(doc.getLength(), "Request URL: ", boldStyle); doc.insertString(doc.getLength(), wsRequest.getURL()+"\n", defaultStyle); doc.insertString(doc.getLength(), "Status: ", boldStyle); if (wsRequest.getErrorMessage() != null) { doc.insertString(doc.getLength(), wsRequest.getErrorMessage()+"\n", errorStyle); } else { doc.insertString(doc.getLength(), wsRequest.isClosed() ? "Closed\n" : wsRequest.getHandshakeResponse() == null ? "Opening\n" : "Open\n", defaultStyle); } } JSONObject requestHeaders = getRequestHeaders(); if (requestHeaders == null) { return; } doc.insertString(doc.getLength(), "\n", defaultStyle); doc.insertString(doc.getLength(), "Request Headers\n", paragraphStyle); printHeaders(pane, requestHeaders, doc, boldStyle, defaultStyle); if (getResponseHeaders() != null) { doc.insertString(doc.getLength(), "\n", defaultStyle); doc.insertString(doc.getLength(), "Response Headers\n", paragraphStyle); printHeaders(pane, getResponseHeaders(), doc, boldStyle, defaultStyle); } }
Example 20
Source File: MatchingHighlighter.java From groovy with Apache License 2.0 | 4 votes |
private void createHighlightedStyleByParen(String p) { Style style = StyleContext.getDefaultStyleContext().addStyle(highlightedStyleName(p), findStyleByTokenType(PAREN_MAP.get(p).getV1())); StyleConstants.setForeground(style, Color.YELLOW.darker()); StyleConstants.setBold(style, true); }