List of usage examples for javax.swing JTextPane setParagraphAttributes
public void setParagraphAttributes(AttributeSet attr, boolean replace)
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 .j a va 2 s .com*/ // 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[] args) { JTextPane pane = new JTextPane(); TabStop[] tabs = new TabStop[1]; tabs[0] = new TabStop(60, TabStop.ALIGN_RIGHT, TabStop.LEAD_NONE); TabSet tabset = new TabSet(tabs); StyleContext sc = StyleContext.getDefaultStyleContext(); AttributeSet aset = sc.addAttribute(SimpleAttributeSet.EMPTY, StyleConstants.TabSet, tabset); pane.setParagraphAttributes(aset, false); pane.setText("\tright\tleft\tcenter\tdecimal\n" + "\t1\t1\t1\t1.0\n" + "\t200.002\t200.002\t200.002\t200.002\n" + "\t.33\t.33\t.33\t.33\n"); JFrame frame = new JFrame("TabExample"); frame.setContentPane(new JScrollPane(pane)); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.setSize(360, 120);//from w w w . ja va2s . c o m frame.setVisible(true); }
From source file:Main.java
public static void main(String[] args) { JTextPane pane = new JTextPane(); TabStop[] tabs = new TabStop[2]; tabs[0] = new TabStop(60, TabStop.ALIGN_RIGHT, TabStop.LEAD_NONE); tabs[1] = new TabStop(100, TabStop.ALIGN_LEFT, TabStop.LEAD_NONE); TabSet tabset = new TabSet(tabs); StyleContext sc = StyleContext.getDefaultStyleContext(); AttributeSet aset = sc.addAttribute(SimpleAttributeSet.EMPTY, StyleConstants.TabSet, tabset); pane.setParagraphAttributes(aset, false); pane.setText("\tright\tleft\tcenter\tValue\n" + "\t200.002\t200.002\t200.002\t200.002\n"); JFrame d = new JFrame(); d.setContentPane(new JScrollPane(pane)); d.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); d.setSize(360, 120);// w ww . j a v a 2 s .c om d.setVisible(true); }
From source file:TabExample.java
public static void main(String[] args) { JTextPane pane = new JTextPane(); TabStop[] tabs = new TabStop[4]; tabs[0] = new TabStop(60, TabStop.ALIGN_RIGHT, TabStop.LEAD_NONE); tabs[1] = new TabStop(100, TabStop.ALIGN_LEFT, TabStop.LEAD_NONE); tabs[2] = new TabStop(200, TabStop.ALIGN_CENTER, TabStop.LEAD_NONE); tabs[3] = new TabStop(300, TabStop.ALIGN_DECIMAL, TabStop.LEAD_NONE); TabSet tabset = new TabSet(tabs); StyleContext sc = StyleContext.getDefaultStyleContext(); AttributeSet aset = sc.addAttribute(SimpleAttributeSet.EMPTY, StyleConstants.TabSet, tabset); pane.setParagraphAttributes(aset, false); pane.setText("\tright\tleft\tcenter\tdecimal\n" + "\t1\t1\t1\t1.0\n" + "\t200.002\t200.002\t200.002\t200.002\n" + "\t.33\t.33\t.33\t.33\n"); JFrame frame = new JFrame("TabExample"); frame.setContentPane(new JScrollPane(pane)); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.setSize(360, 120);//from w w w . ja v a2 s .co m frame.setVisible(true); }
From source file:StylesExample7.java
public static void addText(JTextPane pane, StyleContext sc, Style logicalStyle, Paragraph[] content) { // The outer loop adds paragraphs, while the // inner loop adds character runs. int paragraphs = content.length; for (int i = 0; i < paragraphs; i++) { Run[] runs = content[i].content; for (int j = 0; j < runs.length; j++) { pane.setCharacterAttributes( runs[j].styleName == null ? SimpleAttributeSet.EMPTY : sc.getStyle(runs[j].styleName), true);// w ww . j av a 2 s. c o m pane.replaceSelection(runs[j].content); } // At the end of the paragraph, add the logical style and // any overriding paragraph style and then terminate the // paragraph with a newline. pane.setParagraphAttributes(SimpleAttributeSet.EMPTY, true); if (logicalStyle != null) { pane.setLogicalStyle(logicalStyle); } if (content[i].styleName != null) { pane.setParagraphAttributes(sc.getStyle(content[i].styleName), false); } pane.replaceSelection("\n"); } }
From source file:ExtendedParagraphExample.java
public static void addText(JTextPane pane, StyleContext sc, Style logicalStyle, Paragraph[] content) { // The outer loop adds paragraphs, while the // inner loop adds character runs. int paragraphs = content.length; for (int i = 0; i < paragraphs; i++) { Run[] runs = content[i].content; for (int j = 0; j < runs.length; j++) { pane.setCharacterAttributes( runs[j].styleName == null ? SimpleAttributeSet.EMPTY : sc.getStyle(runs[j].styleName), true);// w w w . j a v a 2 s. c o m pane.replaceSelection(runs[j].content); } // At the end of the paragraph, add the logical style and // any overriding paragraph style and then terminate the // paragraph with a newline. pane.setParagraphAttributes(SimpleAttributeSet.EMPTY, true); if (logicalStyle != null) { pane.setLogicalStyle(logicalStyle); } if (content[i].styleName != null) { pane.setParagraphAttributes(sc.getStyle(content[i].styleName), false); } if (i != paragraphs - 1) { pane.replaceSelection("\n"); } } }