How do you set the tab size in a JEditorPane?

前端 未结 3 2053
后悔当初
后悔当初 2020-12-16 19:17

A JTextArea\'s tab size can easily be set using setTabSize(int).

Is there a similar way to do it with a JEditorPane?

R

3条回答
  •  余生分开走
    2020-12-16 19:40

    In case anyone's using a StyledDocument (The link on the other answer died)

    You create a TabSet which is an array of TabStops. In my case I only cared about the 1st tab, and I wanted it 20px from the left, so this code worked for me:

    StyleContext sc = StyleContext.getDefaultStyleContext();
    TabSet tabs = new TabSet(new TabStop[] { new TabStop(20) });
    AttributeSet paraSet = sc.addAttribute(SimpleAttributeSet.EMPTY, StyleConstants.TabSet, tabs);
    pane.setParagraphAttributes(paraSet, false);
    

提交回复
热议问题