List of usage examples for javax.swing.text StyleConstants setItalic
public static void setItalic(MutableAttributeSet a, boolean b)
From source file:Main.java
public static void main(String[] argv) throws Exception { JTextPane textPane = new JTextPane(); StyledDocument doc = (StyledDocument) textPane.getDocument(); Style style = doc.addStyle("StyleName", null); StyleConstants.setItalic(style, true); doc.insertString(doc.getLength(), "Some Text", style); }
From source file:Main.java
public static void main(String[] argv) throws Exception { JTextPane textPane = new JTextPane(); StyledDocument doc = textPane.getStyledDocument(); // Makes text italicized Style style = textPane.addStyle("Italic", null); StyleConstants.setItalic(style, true); }
From source file:Main.java
public static void main(String[] args) { JTextPane textPane = new JTextPane(); textPane.setText("This is a test string"); StyleConstants.setBold(BOLD, true); StyleConstants.setItalic(ITALIC, true); int start = 5; int end = 10; textPane.getStyledDocument().setCharacterAttributes(start, end - start, BOLD, false); textPane.getStyledDocument().setCharacterAttributes(start, end - start, ITALIC, false); for (int i = start; i < end; i++) System.out.println(//w w w.ja va 2 s.co m textPane.getStyledDocument().getCharacterElement(i).getAttributes().containsAttributes(BOLD)); // all now print true JFrame frame = new JFrame(); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.add(new JScrollPane(textPane)); frame.pack(); frame.setVisible(true); }
From source file:Main.java
public static void main(String[] argv) throws Exception { JTextPane textPane = new JTextPane(); StyledDocument doc = textPane.getStyledDocument(); // A style can have multiple attributes; this one makes text bold and italic Style style = textPane.addStyle("Bold Italic", null); StyleConstants.setBold(style, true); StyleConstants.setItalic(style, 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);// ww w. ja v a2 s. c o m jf.setVisible(true); }
From source file:Main.java
public static void main(String[] args) throws Exception { int cp = 0;//from w ww.j a va2 s .c o m StyledDocument doc; JTextPane jta = new JTextPane(); GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment(); doc = jta.getStyledDocument(); JScrollPane jsp = new JScrollPane(jta); jsp.setPreferredSize(new Dimension(400, 400)); String[] fnt = ge.getAvailableFontFamilyNames(); MutableAttributeSet mas = jta.getInputAttributes(); for (int i = 0; i < fnt.length; i++) { StyleConstants.setBold(mas, false); StyleConstants.setItalic(mas, false); StyleConstants.setFontFamily(mas, fnt[i]); StyleConstants.setFontSize(mas, 16); doc.insertString(cp, fnt[i] + "\n", mas); StyleConstants.setBold(mas, true); doc.insertString(cp, fnt[i] + "bold \n", mas); StyleConstants.setItalic(mas, true); doc.insertString(cp, fnt[i] + "bold and italic\n", mas); StyleConstants.setBold(mas, false); doc.insertString(cp, fnt[i] + "italic\n", mas); } JFrame frm = new JFrame(); frm.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frm.setLayout(new BorderLayout()); frm.add(jsp, BorderLayout.CENTER); frm.setLocation(100, 100); frm.pack(); frm.setVisible(true); }
From source file:StyledSample.java
public static void main(String args[]) { String BOLD_ITALIC = "BoldItalic"; String GRAY_PLAIN = "Gray"; JFrame frame = new JFrame("Simple Attributes"); Container content = frame.getContentPane(); StyledDocument document = new DefaultStyledDocument(); Style style = (Style) document.getStyle(StyleContext.DEFAULT_STYLE); StyleConstants.setBold(style, true); StyleConstants.setItalic(style, true); document.addStyle(BOLD_ITALIC, null); // style = document.getStyle(StyleContext.DEFAULT_STYLE); // StyleConstants.setBold(style, false); // StyleConstants.setItalic(style, false); // StyleConstants.setForeground(style, Color.lightGray); // document.addStyle(GRAY_PLAIN, null); style = document.getStyle(BOLD_ITALIC); // Insert content try {/*ww w.java 2 s . c o m*/ document.insertString(document.getLength(), "Hello Java\n", style); } catch (BadLocationException badLocationException) { System.err.println("Oops"); } style = document.getStyle(GRAY_PLAIN); // Insert content try { document.insertString(document.getLength(), " - Good-bye Visual Basic\n", style); } catch (BadLocationException badLocationException) { System.err.println("Oops"); } JTextPane textPane = new JTextPane(document); textPane.setEditable(false); JScrollPane scrollPane = new JScrollPane(textPane); content.add(scrollPane, BorderLayout.CENTER); frame.setSize(300, 150); 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);//from w w w. j ava 2 s. c om f.pack(); f.setLocationRelativeTo(null); f.setVisible(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 w w w .j av a 2s. c o m frame.add(new JScrollPane(textPane)); frame.setSize(500, 400); frame.setVisible(true); }
From source file:MainClass.java
public static void main(String args[]) throws Exception { JFrame frame = new JFrame("TextPane Example"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); StyleContext context = new StyleContext(); StyledDocument document = new DefaultStyledDocument(context); Style style = context.getStyle(StyleContext.DEFAULT_STYLE); StyleConstants.setAlignment(style, StyleConstants.ALIGN_RIGHT); StyleConstants.setFontSize(style, 14); StyleConstants.setSpaceAbove(style, 4); StyleConstants.setSpaceBelow(style, 4); SimpleAttributeSet attributes = new SimpleAttributeSet(); StyleConstants.setBold(attributes, true); StyleConstants.setItalic(attributes, true); // Third style for icon/component Style labelStyle = context.getStyle(StyleContext.DEFAULT_STYLE); Icon icon = new ImageIcon("Computer.gif"); JLabel label = new JLabel(icon); StyleConstants.setComponent(labelStyle, label); try {//w w w . j a va 2 s. c o m document.insertString(document.getLength(), "Hello www.java2s.com", attributes); document.insertString(document.getLength(), "Ignored", labelStyle); } catch (BadLocationException badLocationException) { System.err.println("Oops"); } JTextPane textPane = new JTextPane(document); textPane.setEditable(false); JScrollPane scrollPane = new JScrollPane(textPane); frame.add(scrollPane, BorderLayout.CENTER); frame.setSize(300, 150); frame.setVisible(true); }