Eddie Eddie - 3 months ago 17
Java Question

How to remove horizontal scroll in JScrollPane?

Is there a way to remove horizontal scroll in a

JScrollPane
that contains a
JTextArea
?

Or make it so that when the text reaches the end, of the line, instead of scrolling horizontally, it prints
"\n"
to start a new line?

Answer

For the scroll pane:

JScrollPane scrollPane = new JScrollPane();
scrollPane.setHorizontalScrollBarPolicy(ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER);

and for the text area (set word wrap):

JTextArea textArea = new JTextArea();
textArea.setLineWrap(true);
textArea.setWrapStyleWord(true);
Comments