StyleConstants: setTabSet(MutableAttributeSet a, TabSet tabs)
import java.awt.BorderLayout;
import javax.swing.JFrame;
import javax.swing.JScrollPane;
import javax.swing.JTextPane;
import javax.swing.text.BadLocationException;
import javax.swing.text.DefaultStyledDocument;
import javax.swing.text.SimpleAttributeSet;
import javax.swing.text.StyleConstants;
import javax.swing.text.StyledDocument;
import javax.swing.text.TabSet;
import javax.swing.text.TabStop;
public class MainClass {
public static void main(final String args[]) {
JFrame frame = new JFrame("Tab Attributes");
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
StyledDocument document = new DefaultStyledDocument();
int positions[] = { TabStop.ALIGN_BAR, TabStop.ALIGN_CENTER, TabStop.ALIGN_DECIMAL,
TabStop.ALIGN_LEFT, TabStop.ALIGN_RIGHT };
String strings[] = { "\tTabStop.ALIGN_BAR\n", "\tTabStop.ALIGN_CENTER\n",
"\tTabStop.ALIGN_DECIMAL\n", "\tTabStop.ALIGN_LEFT\n", "\tTabStop.ALIGN_RIGHT\n" };
SimpleAttributeSet attributes = new SimpleAttributeSet();
for (int i = 0, n = positions.length; i < n; i++) {
TabStop tabstop = new TabStop(150, positions[i], TabStop.LEAD_DOTS);
try {
int position = document.getLength();
document.insertString(position, strings[i], null);
TabSet tabset = new TabSet(new TabStop[] { tabstop });
StyleConstants.setTabSet(attributes, tabset);
document.setParagraphAttributes(position, 1, attributes, false);
} catch (BadLocationException badLocationException) {
System.err.println("Bad Location");
}
}
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);
}
}
Related examples in the same category
1. | StyleConstants.Bold | | |
2. | StyleConstants.Foreground | | |
3. | StyleConstants.Italic | | |
4. | StyleConstants.LineSpacing | | |
5. | StyleConstants: setAlignment(MutableAttributeSet a, int align) | | |
6. | StyleConstants: setBold(MutableAttributeSet a, boolean b) | | |
7. | StyleConstants: setComponent(MutableAttributeSet a, Component c) | | |
8. | StyleConstants: setFirstLineIndent(MutableAttributeSet a, float i) | | |
9. | StyleConstants: setFontFamily(MutableAttributeSet a, String fam) | | |
10. | StyleConstants: setForeground(MutableAttributeSet a, Color fg) | | |
11. | StyleConstants: setFontSize(MutableAttributeSet a, int s) | | |
12. | StyleConstants: setIcon(MutableAttributeSet a, Icon c) | | |
13. | StyleConstants: setItalic(MutableAttributeSet a, boolean b) | | |
14. | StyleConstants: setLeftIndent(MutableAttributeSet a, float i) | | |
15. | StyleConstants: setRightIndent(MutableAttributeSet a, float i) | | |
16. | StyleConstants: setSpaceAbove(MutableAttributeSet a, float i) | | |
17. | StyleConstants: setSpaceBelow(MutableAttributeSet a, float i) | | |
18. | StyleConstants: setUnderline(MutableAttributeSet a, boolean b) | | |