04. april 2002 - 15:02
Der er
1 kommentar og
1 løsning
Set new tab size in a JTextPane
Hello!
I have a class that extends from JTextPane. Now I would like to have an other tab size in this pane, an other then the deafult. JTextArea support this but how do a make it in a JTextPane?
Best regards
Fredrik
Ps I have ide about a Keylistener theat listens for keyEvent-tab and moves everything to a given point but it seems so complicated??
04. april 2002 - 15:11
#1
Noget i retningen af:
private TabSet tabSet = new TabSet(new TabStop[]
{
new TabStop(100),
new TabStop(100),
new TabStop(100)}
);
//set up the styles you want to use in you JTextPane
Style def = StyleContext.getDefaultStyleContext().getStyle(StyleContext.DEFAULT_STYLE);
StyleConstants.setFontFamily(def, regularFont.getFamily());
StyleConstants.setTabSet(def,tabSet);
textPane.setParagraphAttributes(def,true);
Style regular = textPane.addStyle("regular", def);
//Now put tabbed text in the pane:
Document doc = textPane.getDocument();
doc.insertString(doc.getLength(), "\t" + "some text" + NL, textPane.getStyle("regular"));