各位大侠,新手出来咋到,请大家多多包涵。
我希望在文本框中每行输入的字符不大于34个,如果大于34个字符的话自动换行,小于34个字符不换行。
谢谢!!!!
急!!!!
在线等答案!!!!

解决方案 »

  1.   

    public class Test extends JFrame {
    public static void main(String[] args) {
    Test t = new Test();
    t.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    t.setSize(400, 400); final JTextArea area = new JTextArea();
    t.add(area); area.addKeyListener(new KeyAdapter() {
    public void keyReleased(KeyEvent e) {
    String str = area.getText();
    if (str.length() == 34) {
    area.append("\r\n");
    } else if ((str.length() - 34) % 36 == 0) {
    area.append("\r\n");
    }
    }
    }); t.setVisible(true);
    }
    }
    希望你能看懂!
      

  2.   

    正解;不知2楼
    else if ((str.length() - 34) % 36 == 0) {
                        area.append("\r\n");
                    }
    是赶什么用的;不是很明白。请详解一下。
      

  3.   

    感觉应该是这样else if ((str.length() - 34) % 34 == 0) {
                        area.append("\r\n");
                    }