Setting a JTextPane to be center aligned

Any ideas how to do this? I have tried:

private JTextPane pane;

private SimpleAttributeSet set =new SimpleAttributeSet();

StyleConstants.setAlignment(set, StyleConstants.ALIGN_CENTER);

currentDocument = pane.getStyledDocument();

currentDocument.insertString(currentDocument.getLength(), currentToken, set);

Where currentToken is a string... but it just inserts it to the left.

I need the JTextPane to be able to handle some text that is centered, and some that is left aligned, so hard-coding it is not an option.

Thanks for any help

[688 byte] By [abu5ea] at [2007-11-26 21:23:21]
# 1

Nevermind, I have got this bit working, it sets it to centre aligned once, and doesn't ruin the LEFT align.

However, when I set the align back to left, it ruins all the centre alignment, and pushes it all back to LEFT.

I have:

private void setCenterOn() {

StyleConstants.setAlignment(set, StyleConstants.ALIGN_CENTER);

currentDocument.setParagraphAttributes(currentDocument.getLength(), 0, set, false);

}

private void setCenterOff() {

StyleConstants.setAlignment(set, StyleConstants.ALIGN_LEFT);

currentDocument.setParagraphAttributes(currentDocument.getLength(), 0, set, false);

}

Any ideas?

abu5ea at 2007-7-10 3:02:38 > top of Java-index,Java Essentials,Java Programming...
# 2
Thanks anyway, but I solved it.
abu5ea at 2007-7-10 3:02:38 > top of Java-index,Java Essentials,Java Programming...