adalogo.gui.editor

Class NoWrapTextPane


public class NoWrapTextPane
extends JTextPane

JTextPane which does not wrap line (option). The code is inspired from JTextArea which has an option to wrap lines.

Method Summary

Dimension
getPreferredSize()
overriden method to control wrapping behaviour.
boolean
getScrollableTracksViewportWidth()
overriden method to control wrapping behaviour.
void
scrollRectToVisible(Rectangle r)
silly hack to get caret in view when extreme rigth.
void
setLineWrap(boolean wrap)
true to set wrap, false to set no wrap.

Method Details

getPreferredSize

public Dimension getPreferredSize()
overriden method to control wrapping behaviour. copied and modified from JComponent (not from JTextArea because it messes around with fields like rows and columns).

in JTextArea this method will be called from JTextComponent's getScrollableTracksViewportWidth(). overriding this here is necessary because JTextPane does not have this method, and the one from JEditorPane will call getScrollableTracksViewportWidth() which will result in an endless loop.

the call to super.getPreferredSize() should have gone to java.awt.Container, here it would go to JEditorPane, but it seems that it is never called anyway.

See Also:
javax.swing.JEditorPane.getPreferredSize(), javax.swing.JTextArea.getPreferredSize(), javax.swing.JComponent.getPreferredSize(), java.awt.Container.getPreferredSize()


getScrollableTracksViewportWidth

public boolean getScrollableTracksViewportWidth()
overriden method to control wrapping behaviour. copied and modified from JTextArea.

the original code calls super.getScrollableTracksViewportWidth() which would have called the method from JTextComponent. since there is no way to call super.super. the code from JTextComponent was copied.

See Also:
javax.swing.JTextArea.getScrollableTracksViewportWidth(), javax.swing.JTextComponent.getScrollableTracksViewportWidth()


scrollRectToVisible

public void scrollRectToVisible(Rectangle r)
silly hack to get caret in view when extreme rigth.


setLineWrap

public void setLineWrap(boolean wrap)
true to set wrap, false to set no wrap. copied and modified from JTextArea.

See Also:
javax.swing.JTextArea.setLineWrap(boolean)