Horizontal Scrollbar in a JTextPane

How can I specify whether or not there is a horizontal scrollbar for a JTextPane? The JTextPane is held within a JScrollPane, but if I try and do:

scrollPane.setHorizontalScrollBarPolicy(ScrollPaneConstants.HORIZONTAL_SCROLLBAR_ALWAYS);

I just end up with a pointless scrollbar on the JScrollPane which doesn't do anything, because the text in the JTextPane still wraps onto the next line.

Any ideas?

Thank-you.

[443 byte] By [abu5ea] at [2007-11-26 21:35:41]
# 1

Use this code to cancel the line wrapping of the text pane.

JTextPane textPane = new JTextPane() {

public boolean getScrollableTracksViewportWidth() {

return false;

}

public void setSize(Dimension d) {

if (d.width < getParent().getSize().width)

d.width = getParent().getSize().width;

super.setSize(d);

}

};

Rodney_McKaya at 2007-7-10 3:16:23 > top of Java-index,Desktop,Core GUI APIs...