title: How is word-wrapping implemented in JTextPane, and how do I make it wrap a string without spaces?
body: <p>How exactly is word-wrapping implemented in JTextPane?</p>
  
  <p>I'm trying to understand exactly how it works so that I can modify the behavior. Right now, if I have a standard JTextPane inside a JScrollPane, it will break text at spaces, but not inside long words - if there is a string of text without spaces that is wider than the window, it won't wrap/break and a horizontal scrollbar will appear. As the text width increases, the width of the ParagraphView (via getWidth()) increases to hold the text.</p>
  
  <p><a href="http://java-sl.com/wrap.html" rel="noreferrer">This article by Lapitsky</a> says that LabelView.getBreakWeight() returns View.ExcellentBreakWeight for labels with spaces and View.GoodBreakWeight for labels without spaces (and the code in GlyphView.java seems to confirm this), so why doesn't it break? Is it somehow returning BadBreakWeight instead of GoodBreakWeight? Or is there some layout problem? Or is there a bug?</p>
  
  <p>Here's some code (for your viewing pleasure):</p>
  
  <pre><code>//somewhere inside JPanel or JFrame constructor
  JTextPane textPane = new JTextPane();
  JScrollPane scrollPane = new JScrollPane(textPane);
  add(scrollPane);
  </code></pre>
  
  <p>Note that it still doesn't wrap if I take out the scroll pane and just use the text pane (it just gets clipped as it goes outside the window).</p>
  
  <hr>
  
  <p>The javadocs for Swing don't seem to go into enough detail on how some objects (like JTextPane, View's, and related objects) work together. Is there any further documentation of the design of such classes, perhaps detailing the purpose of each class and how they all work together? Is it just not publicly available? (Or am I the only one having trouble with things like this? Or is the insufficient documentation limited to things which aren't expected to be dealt with by a typical developer?)</p>