The Artima Developer Community
Sponsored Link

Legacy Java Answers Forum
November 2000

Advertisement

Advertisement

This page contains an archived post to the Java Answers Forum made prior to February 25, 2002. If you wish to participate in discussions, please visit the new Artima Forums.

Message:

Why do you want to prevent it?

Posted by Kishori Sharan on November 21, 2000 at 9:50 AM

Hi
You need to override the getScrollableTracksViewportWidth () method of JTextPane ( In fact, JTextPane inherits this method from JEditorPane ). If you don't want word + line wrapping then just return false from this method. Run the small program Test.java as given below.

Thanx
Kishori

///////////////////////Test.java //////////
import javax.swing.* ;
import java.awt.* ;


class CstTextPane extends JTextPane {
public CstTextPane() {
super ( ) ;
setSize ( 50, 50 ) ;
}

public boolean getScrollableTracksViewportWidth ( ) {
return false ; // Returning false for non-warpping
}
}

public class Test {

public static void main ( String[] args ) {
String text = "This is a big line of text which won't wrap in text pane" ;
JFrame f = new JFrame ( " J text Pane " ) ;
CstTextPane ctp = new CstTextPane ( );
ctp.setText ( text ) ;
Container cp = f.getContentPane ( ) ;
cp.add ( new JScrollPane ( ctp ) ) ;
cp.add ( new JButton ("Hello" ), "South" ) ;
f.setBounds ( 10, 10, 300, 300 ) ;
f.pack() ;
f.setVisible ( true ) ;
}

}



Replies:

Sponsored Links



Google
  Web Artima.com   
Copyright © 1996-2009 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use - Advertise with Us