This week's book giveaway is in the Jython/Python forum.
We're giving away four copies of Murach's Python Programming and have Michael Urban and Joel Murach on-line!
See this thread for details.
Win a copy of Murach's Python Programming this week in the Jython/Python forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

JTextPane  RSS feed

 
Mario A. Villamizar
Ranch Hand
Posts: 35
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
How can set off the lineWrap in a JTextPane,
I 've been trying with setLineWrap, but only works with JTextArea.
Thanks
 
Chantal Ackermann
Ranch Hand
Posts: 508
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
For what I know, if you want to have no automatic line wrap, but instead a horizontal scrollbar (or whatever) you have to subclass JTextPane (unless they added this functionality in 1.4).

LineWrap-Problem in JTextPane By default JTextPane doesn't support horizontal scrolling, but there are two possibilities to turn the automatic linewrapping definitivly off :
1. Add the JTextPane into a JPanel and then put that in a JScrollPane
2. Override getScrollableTracksViewportWidth()
ExampleCode :

1.
JTextPane pane = new JTextPane() {
public boolean getScrollableTracksViewportWidth() {
return (getSize().width < getParent().getSize().width);
}
public void setSize(Dimension d) {
if (d.width < getParent().getSize().width) {
d.width = getParent().getSize().width;
}
super.setSize(d);
}
};

2.
public boolean getScrollableTracksViewportWidth() {
Component parent = this.getParent();
ComponentUI ui = this.getUI();
return (ui.getPreferredSize(this).width <= parent.getSize().width);
}
(import javax.swing.plaf.*

Example : ScrollingTextPane.java

from: http://www.jalice.net/textfaq.htm
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!