List of usage examples for javax.swing.text StyleConstants setForeground
public static void setForeground(MutableAttributeSet a, Color fg)
From source file:Main.java
public static void main(String[] argv) throws Exception { JTextPane textPane = new JTextPane(); Style style = textPane.addStyle(null, null); StyleConstants.setForeground(style, Color.red); textPane.setLogicalStyle(style);/*from w w w . ja v a 2 s. c o m*/ style = textPane.addStyle(null, null); StyleConstants.setForeground(style, Color.red); textPane.setLogicalStyle(style); }
From source file:Main.java
public static void main(String[] argv) throws Exception { JTextPane textPane = new JTextPane(); Style style = textPane.addStyle(null, null); StyleConstants.setForeground(style, Color.red); textPane.setLogicalStyle(style);/*from w w w. ja v a 2s . co m*/ // Set paragraph style; removes logical style style = textPane.addStyle(null, null); StyleConstants.setUnderline(style, true); textPane.setParagraphAttributes(style, true); // paragraph is now underlined, not red }
From source file:Main.java
public static void main(String[] argv) throws Exception { JTextPane textPane = new JTextPane(); StyledDocument doc = textPane.getStyledDocument(); Style style = textPane.addStyle("Red", null); StyleConstants.setForeground(style, Color.red); // Inherits from "Red"; makes text red and underlined style = textPane.addStyle("Red Underline", style); StyleConstants.setUnderline(style, true); }
From source file:Main.java
public static void main(String[] args) throws Exception { JTextPane textPane = new JTextPane(); StyledDocument doc = textPane.getStyledDocument(); Style style = textPane.addStyle("I'm a Style", null); StyleConstants.setForeground(style, Color.red); doc.insertString(doc.getLength(), "BLAH ", style); StyleConstants.setForeground(style, Color.blue); doc.insertString(doc.getLength(), "BLEH", style); }
From source file:Main.java
public static void main(String[] argv) throws Exception { JTextPane textPane = new JTextPane(); StyledDocument doc = textPane.getStyledDocument(); // Makes text red Style style = textPane.addStyle("Red", null); StyleConstants.setForeground(style, Color.red); }
From source file:Main.java
public static void main(String[] argv) throws Exception { JTextPane textPane = new JTextPane(); StyledDocument doc = (StyledDocument) textPane.getDocument(); // Create a style object and then set the style attributes Style style = doc.addStyle("StyleName", null); StyleConstants.setForeground(style, Color.white); // Append to document doc.insertString(doc.getLength(), "Some Text", style); }
From source file:Main.java
public static void main(String[] argv) throws Exception { JTextPane c1 = new JTextPane(); JTextPane c2 = new JTextPane(); StyleContext styleContext = new StyleContext(); c1.setDocument(new DefaultStyledDocument(styleContext)); c2.setDocument(new DefaultStyledDocument(styleContext)); Style style = c1.addStyle("style name", null); StyleConstants.setForeground(style, Color.red); style = c2.getStyle("style name"); StyleConstants.setBold(style, true); }
From source file:Main.java
public static void main(String[] args) { JFrame frame = new JFrame(); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); StyledDocument doc = new DefaultStyledDocument(); JTextPane textPane = new JTextPane(doc); textPane.setText("this is a test."); Random random = new Random(); for (int i = 0; i < textPane.getDocument().getLength(); i++) { SimpleAttributeSet set = new SimpleAttributeSet(); StyleConstants.setForeground(set, new Color(random.nextInt(256), random.nextInt(256), random.nextInt(256))); StyleConstants.setFontSize(set, random.nextInt(12) + 12); StyleConstants.setBold(set, random.nextBoolean()); StyleConstants.setItalic(set, random.nextBoolean()); StyleConstants.setUnderline(set, random.nextBoolean()); doc.setCharacterAttributes(i, 1, set, true); }//from www. java2 s . c om frame.add(new JScrollPane(textPane)); frame.setSize(500, 400); frame.setVisible(true); }
From source file:Main.java
public static void main(String[] args) throws Exception { JFrame f = new JFrame(); f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); String s = new Date().toString(); JTextPane jtp = new JTextPane(); StyledDocument doc = (StyledDocument) jtp.getDocument(); SimpleAttributeSet normal = new SimpleAttributeSet(); StyleConstants.setFontFamily(normal, "SansSerif"); StyleConstants.setFontSize(normal, 16); SimpleAttributeSet boldBlue = new SimpleAttributeSet(normal); StyleConstants.setBold(boldBlue, true); StyleConstants.setForeground(boldBlue, Color.blue); SimpleAttributeSet highAlert = new SimpleAttributeSet(boldBlue); StyleConstants.setFontSize(highAlert, 18); StyleConstants.setItalic(highAlert, true); StyleConstants.setForeground(highAlert, Color.red); doc.insertString(doc.getLength(), s + "\n", normal); doc.insertString(doc.getLength(), s + "\n", boldBlue); doc.insertString(doc.getLength(), s + "\n", highAlert); f.add(jtp);// www . java 2 s . com f.pack(); f.setLocationRelativeTo(null); f.setVisible(true); }
From source file:Main.java
public static void main(String args[]) throws BadLocationException { JFrame jf = new JFrame("StyledText"); jf.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); Container cp = jf.getContentPane(); JTextPane pane = new JTextPane(); SimpleAttributeSet set = new SimpleAttributeSet(); StyleConstants.setBold(set, true); // Set the attributes before adding text pane.setCharacterAttributes(set, true); pane.setText("java2s.com "); set = new SimpleAttributeSet(); StyleConstants.setItalic(set, true); StyleConstants.setForeground(set, Color.red); StyleConstants.setBackground(set, Color.blue); Document doc = pane.getStyledDocument(); doc.insertString(doc.getLength(), "Swing ", set); set = new SimpleAttributeSet(); StyleConstants.setFontSize(set, 24); doc.insertString(doc.getLength(), "Tutorial", set); JScrollPane scrollPane = new JScrollPane(pane); cp.add(scrollPane, BorderLayout.CENTER); jf.setSize(400, 300);//from ww w . j av a 2s . c o m jf.setVisible(true); }