2 Replies Latest reply: Oct 22, 2012 11:43 AM by DrClap RSS

    limited characters in textarea using swings

      i have one text area that is created using swings technologies now this text area need to allow only 30 characters perline and limit of the text area is maxmium of 500 characters.
      i have done some coding but it breaks whenever the copy/paste happens(i.e it allowing more than 30 characters perline).Can anybody provide the solution ASAP.
      Thanks in advance
        • 1. Re: limited characters in textarea using swings
          1. This question should go into the swing forum.
          2. Write your own TextArea (extends JTextArea). In this class get the document with
          AbstractDocument doc = (AbstractDocument)this.getDocument();
          Then write your own Document filter (extends DocumentFilter) and set this filter to the document
          In the filter you have full control over of what is inserted in your text area.
          • 2. Re: limited characters in textarea using swings
            And there's an example in the API documentation for JTextField about how to use a Document to control the input. You could easily modify that example to restrict the length of the field's data.