First, I am a newbie in Java programming. I want to disable the word-wraping in JTextPane cause there's no such options to do it unlike JTextArea. I got this one solution but I don't know how to implement it, like where should I place it in my code?
No Wrap implementation:
public class NoWrapParagraphView extends ParagraphView {
public NoWrapParagraphView(Element elem) {
super(elem);
}
@Override
public void layout(int width, int height) {
super.layout(Short.MAX_VALUE, height);
}
@Override
public float getMinimumSpan(int axis) {
return super.getPreferredSpan(axis);
}
}
JTextArea and JScrollPane:
/*-- OTHER CODES --*/
JTextPane jTextPane = new JTextPane();
jTextPane.setContentType("text/html");
jTextPane.setEditable(false);
JScrollPane jScrollPane = new JScrollPane();
jScrollPane.setViewportView(jTextPane);
/*-- MORE CODES --*/
Check out No Wrap Text Pane for potentially simpler solutions.
These solutions override the default
Scrollable
interface used by aJTextPane
to prevent wrapping.