• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Word wrap and other issues with JTextPane

 
Ranch Hand
Posts: 50
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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?

 
Rancher
Posts: 3324
32
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
See: No Wrap Text Pane.
 
Poorav Chaudhari
Ranch Hand
Posts: 50
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.

reply
    Bookmark Topic Watch Topic
  • New Topic