Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Word wrap and other issues with JTextPane

 
Poorav Chaudhari
Ranch Hand
Posts: 50
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am using NetBeans to develop my swing application. I have one JTextPane which I have placed within a JScrollPane. My first issue was to disable the line wrap. To do this I extended the JTextPane and overrode the getScrollableTracksViewportWidth() to return false. The problem I have is that once i created a wrapper for the JTextPane, when I run the application the width of the TextPane is 0 and when I start typing in the in the textpane it expands. I would like the size of the textpane to be the size of the scrollpane. Please tell me what I am missing. If i change the textpane definition to JTextPane() then the size of the textPane is the size of the scrollPane, but then obviously the line wrapping is enabled. So here is what I have

The textPane is defined as


And this is the code generated for the initialization of the textPane


I hope I am clear enough. Any idea what I can do to make sure the textPane is the same size of the scrollPane?

 
Rob Camick
Ranch Hand
Posts: 2583
9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
See: No Wrap Text Pane.
 
Poorav Chaudhari
Ranch Hand
Posts: 50
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you all for your input. What I ended up doing was to modify the getScrollableTracksViewportWidth() method as following.



I picked up this snippet from http://www.java2s.com/Code/Java/Swing-JFC/NonWrappingWrapTextPane.htm.

 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic