Toggling text wrap in a JTextpane

java, jtextpane, swing, word-wrap

Solution

See No Wrap Text Pane.

Edit:

Well, if you want to toggle the behaviour, then you would also need to toggle the getScrollableTracksViewportWidth() value. See Scrollable Panel. You should be able to toggle between FIT and STRETCH.

Problem

How would I go about toggling text wrap on a `JTextpane`? ``` public JFrame mainjFrame = new JFrame("Text Editor"); public JTextPane mainJTextPane = new JTextPane(); public JScrollPane mainJScrollPane = new JScrollPane(mainJTextPane); mainjFrame.add(mainJScrollPane); ```

Original source