JTextPane: setParagraphAttributes(AttributeSet attr, boolean replace) : JTextPane « javax.swing « Java by API






JTextPane: setParagraphAttributes(AttributeSet attr, boolean replace)

  
import javax.swing.JFrame;
import javax.swing.JScrollPane;
import javax.swing.JTextPane;
import javax.swing.text.AttributeSet;
import javax.swing.text.SimpleAttributeSet;
import javax.swing.text.StyleConstants;
import javax.swing.text.StyleContext;
import javax.swing.text.TabSet;
import javax.swing.text.TabStop;

public class Main {
  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);
    frame.setVisible(true);
  }
}

   
    
  








Related examples in the same category

1.JTextPane: getDocument()
2.JTextPane: getStyledDocument()
3.JTextPane: insertComponent(Component c)
4.JTextPane: insertIcon(Icon g)
5.JTextPane: replaceSelection(String content)
6.JTextPane: setCaretPosition(int position)
7.JTextPane.setCharacterAttributes(AttributeSet attr, boolean replace)
8.JTextPane: setFont(Font font)
9.JTextPane: setLogicalStyle(Style s)