javaswingjtextpane

How to turn off JTextPane line wrapping?


Unlike JTextArea, JTextPane has no option to turn line wrapping off. I found one solution to turning off line wrapping in JTextPanes, but it seems too verbose for such a simple problem. Is there a better way to do this?


Solution

  • See No Wrap Text Pane. Here's the code included from the link.

    JTextPane textPane = new JTextPane();
    JPanel noWrapPanel = new JPanel( new BorderLayout() );
    noWrapPanel.add( textPane );
    JScrollPane scrollPane = new JScrollPane( noWrapPanel );