Java Code Examples for javax.swing.JTextPane#addStyle()
The following examples show how to use
javax.swing.JTextPane#addStyle() .
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: SummaryCellRenderer.java From netbeans with Apache License 2.0 | 4 votes |
private Style createNormalStyle (JTextPane textPane) { Style normalStyle = textPane.addStyle("normal", null); //NOI18N StyleConstants.setForeground(normalStyle, UIManager.getColor("List.foreground")); //NOI18N return normalStyle; }
Example 2
Source File: SummaryCellRenderer.java From netbeans with Apache License 2.0 | 4 votes |
private Style createIssueHyperlinkStyle (JTextPane textPane, Style normalStyle) { Style issueHyperlinkStyle = textPane.addStyle("issuehyperlink", normalStyle); //NOI18N StyleConstants.setForeground(issueHyperlinkStyle, LINK_COLOR == null ? Color.BLUE : LINK_COLOR); StyleConstants.setUnderline(issueHyperlinkStyle, true); return issueHyperlinkStyle; }
Example 3
Source File: SummaryCellRenderer.java From netbeans with Apache License 2.0 | 4 votes |
private Style createAuthorStyle (JTextPane textPane, Style normalStyle) { Style authorStyle = textPane.addStyle("author", normalStyle); //NOI18N StyleConstants.setForeground(authorStyle, LINK_COLOR == null ? Color.BLUE : LINK_COLOR); return authorStyle; }
Example 4
Source File: SummaryCellRenderer.java From netbeans with Apache License 2.0 | 4 votes |
private Style createLinkStyle (JTextPane textPane, Style normalStyle) { Style linkStyle = textPane.addStyle("link", normalStyle); //NOI18N StyleConstants.setForeground(linkStyle, LINK_COLOR == null ? Color.BLUE : LINK_COLOR); StyleConstants.setBold(linkStyle, true); return linkStyle; }
Example 5
Source File: SummaryCellRenderer.java From netbeans with Apache License 2.0 | 4 votes |
private Style createNoindentStyle (JTextPane textPane) { Style noindentStyle = textPane.addStyle("noindent", null); //NOI18N StyleConstants.setLeftIndent(noindentStyle, 0); return noindentStyle; }
Example 6
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 7
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 8
Source File: OSPLog.java From osp with GNU General Public License v3.0 | 4 votes |
/** * Creates the GUI. */ protected void createGUI() { // create the panel, text pane and scroller logPanel = new JPanel(new BorderLayout()); logPanel.setPreferredSize(new Dimension(480, 240)); setContentPane(logPanel); textPane = new JTextPane() { public void paintComponent(Graphics g) { if(OSPRuntime.antiAliasText) { Graphics2D g2 = (Graphics2D) g; RenderingHints rh = g2.getRenderingHints(); rh.put(RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_ON); rh.put(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); } super.paintComponent(g); } }; textPane.setEditable(false); textPane.setAutoscrolls(true); JScrollPane textScroller = new JScrollPane(textPane); textScroller.setWheelScrollingEnabled(true); logPanel.add(textScroller, BorderLayout.CENTER); // create the colored styles black = StyleContext.getDefaultStyleContext().getStyle(StyleContext.DEFAULT_STYLE); red = textPane.addStyle("red", black); //$NON-NLS-1$ StyleConstants.setForeground(red, DARK_RED); blue = textPane.addStyle("blue", black); //$NON-NLS-1$ StyleConstants.setForeground(blue, DARK_BLUE); green = textPane.addStyle("green", black); //$NON-NLS-1$ StyleConstants.setForeground(green, DARK_GREEN); magenta = textPane.addStyle("magenta", black); //$NON-NLS-1$ StyleConstants.setForeground(magenta, Color.MAGENTA); gray = textPane.addStyle("gray", black); //$NON-NLS-1$ StyleConstants.setForeground(gray, Color.GRAY); // create the logger createLogger(); // create the menus createMenus(); pack(); textPane.addMouseListener(new MouseAdapter() { public void mousePressed(MouseEvent e) { try { if(OSPRuntime.isPopupTrigger(e)) { // show popup menu if(popup!=null) { FontSizer.setFonts(popup, FontSizer.getLevel()); popup.show(textPane, e.getX(), e.getY()+8); } } } catch(Exception ex) { System.err.println("Error in mouse action."); //$NON-NLS-1$ System.err.println(ex.toString()); ex.printStackTrace(); } } }); }