Java examples for Swing:JTextPane
Customizing Tab Stops in a JTextPane Component
import java.util.ArrayList; import javax.swing.JTextPane; import javax.swing.text.Style; import javax.swing.text.StyleConstants; import javax.swing.text.TabSet; import javax.swing.text.TabStop; public class Main { public void main(String[] argv) { JTextPane textPane = new JTextPane(); java.util.List list = new ArrayList(); // Create a left-aligned tab stop at 100 pixels from the left margin float pos = 100; int align = TabStop.ALIGN_LEFT; int leader = TabStop.LEAD_NONE; TabStop tstop = new TabStop(pos, align, leader); list.add(tstop);//from w w w . j av a 2s. co m // Create a right-aligned tab stop at 200 pixels from the left margin pos = 200; align = TabStop.ALIGN_RIGHT; leader = TabStop.LEAD_NONE; tstop = new TabStop(pos, align, leader); list.add(tstop); // Create a center-aligned tab stop at 300 pixels from the left margin pos = 300; align = TabStop.ALIGN_CENTER; leader = TabStop.LEAD_NONE; tstop = new TabStop(pos, align, leader); list.add(tstop); // Create a decimal-aligned tab stop at 400 pixels from the left margin pos = 400; align = TabStop.ALIGN_DECIMAL; leader = TabStop.LEAD_NONE; tstop = new TabStop(pos, align, leader); list.add(tstop); TabStop[] tstops = (TabStop[]) list.toArray(new TabStop[0]); TabSet tabs = new TabSet(tstops); Style style = textPane.getLogicalStyle(); StyleConstants.setTabSet(style, tabs); textPane.setLogicalStyle(style); } }