如果您正在使用Swing和JTextArea,请尝试使用setWrapStyleWord和setLineWrap方法:
textarea.setWrapStyleWord(true);
textarea.setLineWrap(true);
Run Code Online (Sandbox Code Playgroud)
您还需要设置JTextArea的列数:
private static final int TA_ROWS = 20;
private static final int TA_COLS = 35;
private JTextArea textarea = new JTextArea(TA_ROWS, TA_COLS);
Run Code Online (Sandbox Code Playgroud)
并将JTextArea包装在JScrollPane中.
编辑
我假设您正在使用Swing,但在重新阅读您的问题时我可能错了.这是为Swing吗?AWT?Android的?其他?