JTextArea行中字符的限制

Ari*_*jas 1 java swing rows jtextarea

如何限制JTextArea行中的字符数,并使其跳到第二个?

Hov*_*els 9

如果您正在使用Swing和JTextArea,请尝试使用setWrapStyleWordsetLineWrap方法:

  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的?其他?