Java Code Examples for javax.swing.text.StyleConstants#setBackground()
The following examples show how to use
javax.swing.text.StyleConstants#setBackground() .
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: DisplayArea.java From android-classyshark with Apache License 2.0 | 6 votes |
@Override public void displayClass(List<Translator.ELEMENT> elements, String key) { displayDataState = DisplayDataState.INSIDE_CLASS; clearText(); StyleConstants.setFontSize(style, 20); StyleConstants.setBackground(style, theme.getBackgroundColor()); Document doc = new DefaultStyledDocument(); fillTokensToDoc(elements, doc, false); StyleConstants.setForeground(style, theme.getIdentifiersColor()); jTextPane.setDocument(doc); int i = calcScrollingPosition(key); jTextPane.setCaretPosition(i); }
Example 2
Source File: AnnotationDisplayCustomizationFrame.java From uima-uimaj with Apache License 2.0 | 6 votes |
@Override public void actionPerformed(ActionEvent event) { Style style = AnnotationDisplayCustomizationFrame.this.styleMap .get(AnnotationDisplayCustomizationFrame.this.currentTypeName); if (style == null) { style = AnnotationDisplayCustomizationFrame.this.textPane.addStyle( AnnotationDisplayCustomizationFrame.this.currentTypeName, AnnotationDisplayCustomizationFrame.this.styleMap.get(CAS.TYPE_NAME_ANNOTATION)); } StyleConstants.setForeground(style, StyleConstants .getForeground(AnnotationDisplayCustomizationFrame.this.currentStyle)); StyleConstants.setBackground(style, StyleConstants .getBackground(AnnotationDisplayCustomizationFrame.this.currentStyle)); AnnotationDisplayCustomizationFrame.this.styleMap.put( AnnotationDisplayCustomizationFrame.this.currentTypeName, style); enableButtons(false); AnnotationDisplayCustomizationFrame.this.repaint(); }
Example 3
Source File: StackTraceColorizer.java From otroslogviewer with Apache License 2.0 | 6 votes |
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); }
Example 4
Source File: ComponentController.java From swingsane with Apache License 2.0 | 6 votes |
private void addMessage(String message) { StyledDocument doc = components.getMessagesTextPane().getStyledDocument(); SimpleAttributeSet keyWord = new SimpleAttributeSet(); StyleConstants.setForeground(keyWord, Color.GREEN); StyleConstants.setBackground(keyWord, Color.BLUE); StyleConstants.setBold(keyWord, true); try { if (message.toLowerCase().startsWith("found ")) { doc.insertString(0, message + "\n", keyWord); } else { doc.insertString(0, message + "\n", null); } } catch (BadLocationException e) { LOG.error(e, e); } }
Example 5
Source File: BaseTypeTableCellRenderer.java From binnavi with Apache License 2.0 | 5 votes |
private static Style createDataStyle(final StyledDocument document) { final Style declStyle = document.addStyle("DATA_STYLE", null); StyleConstants.setBackground(declStyle, Color.WHITE); StyleConstants.setForeground(declStyle, Color.BLUE); StyleConstants.setFontFamily(declStyle, GuiHelper.getMonospaceFont()); StyleConstants.setFontSize(declStyle, 11); return declStyle; }
Example 6
Source File: TextEditorGUI.java From trygve with GNU General Public License v2.0 | 5 votes |
public void removeAllBreakpoints() { final StyledDocument doc = (StyledDocument)editPane.getDocument(); final SimpleAttributeSet sas = new SimpleAttributeSet(); StyleConstants.setBackground(sas, new java.awt.Color(233, 228, 242)); // https://stackoverflow.com/questions/28927274/get-attributes-of-selected-text-in-jtextpane for(int i = 0; i < doc.getLength(); i++) { final AttributeSet set = doc.getCharacterElement(i).getAttributes(); final Color backgroundColor = StyleConstants.getBackground(set); if (backgroundColor.equals(Color.cyan)) { // The breakpoint color. Remove breakpoint annotation from this text doc.setCharacterAttributes(i, 1, sas, false); } } }
Example 7
Source File: SoapMessageColorizer.java From otroslogviewer with Apache License 2.0 | 5 votes |
private void initStyles() { StyleContext sc = new StyleContext(); Style parent = sc.getStyle(StyleContext.DEFAULT_STYLE); StyleConstants.setFontFamily(parent, "courier"); StyleConstants.setFontSize(parent, 13); styleElementName = sc.addStyle("elementName", parent); StyleConstants.setForeground(styleElementName, theme.getColor(ThemeKey.LOG_DETAILS_SOAP_ELEMENT_NAME)); styleAttributeName = sc.addStyle("attributeName", parent); StyleConstants.setForeground(styleAttributeName, theme.getColor(ThemeKey.LOG_DETAILS_SOAP_ATTRIBUTE_NAME)); styleAttributeValue = sc.addStyle("attributeValue", parent); StyleConstants.setForeground(styleAttributeValue, theme.getColor(ThemeKey.LOG_DETAILS_SOAP_ATTRIBUTE_VALUE)); styleContent = sc.addStyle("content", parent); StyleConstants.setBackground(styleContent, theme.getColor(ThemeKey.LOG_DETAILS_SOAP_CONTENT_BACKGROUND)); StyleConstants.setForeground(styleContent, theme.getColor(ThemeKey.LOG_DETAILS_SOAP_CONTENT_FOREGROUND)); styleOperator = sc.addStyle("operator", parent); StyleConstants.setForeground(styleOperator, theme.getColor(ThemeKey.LOG_DETAILS_SOAP_OPERATOR)); StyleConstants.setBold(styleOperator, true); styleComments = sc.addStyle("comments", parent); StyleConstants.setForeground(styleComments, theme.getColor(ThemeKey.LOG_DETAILS_SOAP_COMMENTS)); styleCData = sc.addStyle("cdata", parent); StyleConstants.setForeground(styleCData, theme.getColor(ThemeKey.LOG_DETAILS_SOAP_CDATA_FOREGROUND)); StyleConstants.setBackground(styleCData, theme.getColor(ThemeKey.LOG_DETAILS_SOAP_CDATA_BACKGROUND)); styleDOCTYPE = sc.addStyle("doctype", sc.addStyle("doctype", parent)); }
Example 8
Source File: StyledConsoleLogger.java From importer-exporter with Apache License 2.0 | 5 votes |
public void applyLogLevelStyle(LogLevel level, LogLevelStyle logLevelStyle) { Style style = context.getStyle(level.value()); Color foreground = GuiUtil.hexToColor(logLevelStyle.getForeground()); if (foreground != null) StyleConstants.setForeground(style, foreground); else style.removeAttribute(StyleConstants.Foreground); Color background = GuiUtil.hexToColor(logLevelStyle.getBackground()); if (background != null) StyleConstants.setBackground(style, background); else style.removeAttribute(StyleConstants.Background); }
Example 9
Source File: AnnotationDisplayCustomizationFrame.java From uima-uimaj with Apache License 2.0 | 5 votes |
/** * Sets the current style. * * @param style the new current style */ private void setCurrentStyle(Style style) { // Copy style. this.currentStyle = this.textPane.addStyle(currentStyleName, style); StyleConstants.setForeground(this.currentStyle, StyleConstants.getForeground(style)); StyleConstants.setBackground(this.currentStyle, StyleConstants.getBackground(style)); }
Example 10
Source File: MWPaneFormatter.java From wpcleaner with Apache License 2.0 | 5 votes |
/** * Modify the background color of a style. * * @param style Style to be modified. * @param config Configuration. * @param configStyle Configuration of the style. */ private static void formatStyleBackground( Style style, Configuration config, ConfigurationValueStyle.StyleProperties configStyle) { if ((style == null) || (config == null) || (configStyle == null)) { return; } if (!configStyle.getBackground()) { return; } StyleConstants.setBackground(style, configStyle.getBackgroundColor()); }
Example 11
Source File: BaseTypeTableCellRenderer.java From binnavi with Apache License 2.0 | 5 votes |
private static Style createDeclarationStyle(final StyledDocument document) { final Style declStyle = document.addStyle("DECL_STYLE", null); StyleConstants.setBackground(declStyle, Color.WHITE); StyleConstants.setForeground(declStyle, Color.BLACK); StyleConstants.setFontFamily(declStyle, GuiHelper.getMonospaceFont()); StyleConstants.setFontSize(declStyle, 11); return declStyle; }
Example 12
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 13
Source File: TextEditorGUI.java From trygve with GNU General Public License v2.0 | 5 votes |
public ArrayList<Integer> breakpointByteOffsets() { State state = State.LookingForField; ArrayList<Integer> retval = new ArrayList<Integer>(); final StyledDocument doc = (StyledDocument)editPane.getDocument(); final SimpleAttributeSet breakpointColored = new SimpleAttributeSet(); StyleConstants.setBackground(breakpointColored, Color.cyan); for(int i = 0; i < doc.getLength(); i++) { final Element element = doc.getCharacterElement(i); final AttributeSet set = element.getAttributes(); final Color backgroundColor = StyleConstants.getBackground(set); switch (state) { case LookingForField: if (true == backgroundColor.equals(Color.cyan)) { state = State.InField; retval.add(new Integer(i)); } break; case InField: if (false == backgroundColor.equals(Color.cyan)) { state = State.LookingForField; } else if (element.toString().equals("\n")) { state = State.LookingForField; } break; default: assert (false); break; } } return retval; }
Example 14
Source File: AnnotationColorsPanel.java From netbeans with Apache License 2.0 | 5 votes |
public synchronized List<AttributeSet> getColorAttributes() { ArrayList<AttributeSet> attrs = this.colorAttributes; if (attrs == null) { attrs = new ArrayList<AttributeSet>(colors.size()); for (Map.Entry<String, Color[]> e : colors.entrySet()) { SimpleAttributeSet sas = new SimpleAttributeSet (); StyleConstants.setBackground(sas, e.getValue()[0]); sas.addAttribute(StyleConstants.NameAttribute, e.getKey()); sas.addAttribute(EditorStyleConstants.DisplayName, e.getKey()); attrs.add(sas); } this.colorAttributes = attrs; } return attrs; }
Example 15
Source File: TextEditorGUI.java From trygve with GNU General Public License v2.0 | 5 votes |
public void setBreakpointToEOLAt(int byteOffset, int lineNumber) { final StyledDocument doc = (StyledDocument)editPane.getDocument(); final Element paragraphElement = doc.getParagraphElement(byteOffset); if (paragraphElement.getClass() == BranchElement.class) { final SimpleAttributeSet sas = new SimpleAttributeSet(); StyleConstants.setBackground(sas, Color.cyan); // Look for ending delimiter int length = 1; try { for (int i = byteOffset; ; i++) { if (i >= doc.getLength()) { length = i - byteOffset + 1; break; } else if (doc.getText(i, 1).equals("\n")) { length = i - byteOffset; break; } } } catch (BadLocationException ble) { length = 0; } if (0 < length) { doc.setCharacterAttributes(byteOffset, length, sas, false); } } }
Example 16
Source File: RevisionListPanel.java From netbeans with Apache License 2.0 | 5 votes |
public RevisionRenderer () { selectionBackground = new JList().getSelectionBackground(); selectionForeground = new JList().getSelectionForeground(); selectedStyle = addStyle("selected", null); // NOI18N StyleConstants.setForeground(selectedStyle, selectionForeground); // NOI18N StyleConstants.setBackground(selectedStyle, selectionBackground); // NOI18N normalStyle = addStyle("normal", null); // NOI18N StyleConstants.setForeground(normalStyle, UIManager.getColor("List.foreground")); // NOI18N setLayout(new BorderLayout()); setBorder(null); }
Example 17
Source File: GuiUtil.java From FancyBing with GNU General Public License v3.0 | 5 votes |
public static void addStyle(JTextPane textPane, String name, Color foreground, Color background, boolean bold) { StyledDocument doc = textPane.getStyledDocument(); StyleContext context = StyleContext.getDefaultStyleContext(); Style def = context.getStyle(StyleContext.DEFAULT_STYLE); Style style = doc.addStyle(name, def); if (foreground != null) StyleConstants.setForeground(style, foreground); if (background != null) StyleConstants.setBackground(style, background); StyleConstants.setBold(style, bold); }
Example 18
Source File: AnnotationDisplayCustomizationFrame.java From uima-uimaj with Apache License 2.0 | 5 votes |
@Override public void actionPerformed(ActionEvent event) { Color color = JColorChooser.showDialog(AnnotationDisplayCustomizationFrame.this, "Choose color", AnnotationDisplayCustomizationFrame.this.bgColor); if (color != null) { AnnotationDisplayCustomizationFrame.this.bgColor = color; AnnotationDisplayCustomizationFrame.this.bgIcon.setColor(color); StyleConstants.setBackground(AnnotationDisplayCustomizationFrame.this.currentStyle, color); setTextPane(); enableButtons(true); AnnotationDisplayCustomizationFrame.this.repaint(); } }
Example 19
Source File: SummaryCellRenderer.java From netbeans with Apache License 2.0 | 4 votes |
private Style createSelectedStyle (JTextPane textPane) { Style selectedStyle = textPane.addStyle("selected", null); //NOI18N StyleConstants.setForeground(selectedStyle, selectionForeground); StyleConstants.setBackground(selectedStyle, selectionBackground); return selectedStyle; }
Example 20
Source File: ViewPane.java From aion-germany with GNU General Public License v3.0 | 4 votes |
private void addStylesToHexDump(StyledDocument doc) { Style def = StyleContext.getDefaultStyleContext().getStyle(StyleContext.DEFAULT_STYLE); Style base = doc.addStyle("base", def); StyleConstants.setFontFamily(base, "Monospaced"); Style regular = doc.addStyle("regular", base); //StyleConstants.setUnderline(regular , true); Style s = doc.addStyle("d", regular); StyleConstants.setBackground(s, new Color(72, 164, 255)); s = doc.addStyle("dbs", regular); StyleConstants.setBackground(s, new Color(72, 164, 255)); s = doc.addStyle("Q", regular); StyleConstants.setBackground(s, new Color(255, 255, 128)); s = doc.addStyle("h", regular); StyleConstants.setBackground(s, Color.ORANGE); s = doc.addStyle("hbs", regular); StyleConstants.setBackground(s, Color.ORANGE); s = doc.addStyle("s", regular); StyleConstants.setBackground(s, new Color(156, 220, 156)); s = doc.addStyle("S", regular); StyleConstants.setBackground(s, new Color(156, 220, 156)); s = doc.addStyle("c", regular); StyleConstants.setBackground(s, Color.PINK); s = doc.addStyle("cbs", regular); StyleConstants.setBackground(s, Color.PINK); s = doc.addStyle("f", regular); StyleConstants.setBackground(s, Color.LIGHT_GRAY); Color bxColor = new Color(255, 234, 213); s = doc.addStyle("b", regular); StyleConstants.setBackground(s, bxColor); s = doc.addStyle("x", regular); StyleConstants.setBackground(s, bxColor); s = doc.addStyle("op", regular); StyleConstants.setBackground(s, Color.YELLOW); s = doc.addStyle("selected", regular); StyleConstants.setBackground(s, Color.BLUE); s = doc.addStyle("chk", regular); StyleConstants.setBackground(s, Color.GREEN); }