user3548003 user3548003 - 4 months ago 38
Java Question

How to disable WordWrap in Java JTextPane?

My program has a problem.. It is WordWrap is abled...

Exactly, I want to use linwrap but i don't want wordwrap...

I searched this

JTextPane textPane = new JTextPane();
JPanel noWrapPanel = new JPanel( new BorderLayout() );
noWrapPanel.add( textPane );
JScrollPane scrollPane = new JScrollPane( noWrapPanel );


When i use this code, Both linewrap and wordwrap are disabled....

I want to make use linewrap....

sorry my terrible English skill...
I believe you can get what i mean
please help me...

Answer

Here it is :

Link for it

// Override getScrollableTracksViewportWidth
// to preserve the full width of the text
public boolean getScrollableTracksViewportWidth() {
    Component parent = getParent();
    ComponentUI ui = getUI();

    return parent != null ? (ui.getPreferredSize(this).width <= parent
        .getSize().width) : true;
}

Other link