Setting the tab policy in Swing's JTextPane
问题 I want my JTextPane to insert spaces whenever I press Tab. Currently it inserts the tab character (ASCII 9). Is there anyway to customize the tab policy of JTextPane (other than catching "tab-key" events and inserting the spaces myself seems an)? 回答1: You can set a javax.swing.text.Document on your JTextPane. The following example will give you an idea of what I mean :) import java.awt.Dimension; import javax.swing.JFrame; import javax.swing.JTextPane; import javax.swing.text.AttributeSet;