如何删除 JScrollPane 中的水平滚动?

How to remove horizontal scroll in JScrollPane?

有没有办法删除包含 JTextAreaJScrollPane 中的水平滚动?

或者当文本到达行尾时,不是水平滚动,而是打印 "\n" 开始新行?

对于滚动窗格:

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

对于文本区域(设置自动换行):

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

编辑: 如评论中所述,第一部分(划掉)是多余的