Results 1 to 4 of 4
Like Tree1Likes
  • 1 Post By taptaptill

Thread: JTextArea differenet methode of inserting text

  1. #1
    taptaptill is offline Member
    Join Date
    Dec 2012
    Posts
    32
    Rep Power
    0

    Default JTextArea differenet methode of inserting text

    Hello Everyone and thanks for the help in advance :)
    So I want to know if it's possible in a textarea to know the input method like from the keyboard or from the code, cause I want to make part of a text area uneditable while it's editable what I mean is before the postion of the caret the text can not be modified.

  2. #2
    DarrylBurke's Avatar
    DarrylBurke is offline Moderator
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    9,944
    Rep Power
    16

    Default Re: JTextArea differenet methode of inserting text

    Looks like you what you need is camickr's Protected Text Component « Java Tips Weblog

    db
    Why do they call it rush hour when nothing moves? - Robin Williams

  3. #3
    taptaptill is offline Member
    Join Date
    Dec 2012
    Posts
    32
    Rep Power
    0

    Default Re: JTextArea differenet methode of inserting text

    thanks for the response it's done!! :)
    For anyone how might need it, this is the code :
    Java Code:
       private class Filter extends DocumentFilter {
          
        
            int caretpos = Traffic.getCaretPosition();
            @Override
            public void insertString(final FilterBypass fb, final int offset, final String string, final AttributeSet attr)
                throws BadLocationException {
            if (offset > 0 ){
                super.insertString(fb, offset, string, attr);
            }
              
            }
        
          @Override
        public void remove(final DocumentFilter.FilterBypass fb, final int offset, final int length) throws BadLocationException {
            
              if (  (Traffic.getLineStartOffset(Traffic.getLineCount()-1) + promptposition()) - 1 < offset && (Traffic.getLineOfOffset(offset)  == (Traffic.getLineCount() - 1)) ){
              
                super.remove(fb, offset , length);
                
               
            
        }}
    
          @Override
        public void replace(final DocumentFilter.FilterBypass fb, final int offset, final int length, final String text, final AttributeSet attrs)
                throws BadLocationException {
            if (offset >= promptposition() ) {
                super.replace(fb,offset, length, text, attrs);
                
               
                
            }
        }
    }
    DarrylBurke likes this.

  4. #4
    DarrylBurke's Avatar
    DarrylBurke is offline Moderator
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    9,944
    Rep Power
    16

    Default Re: JTextArea differenet methode of inserting text

    Thank you for posting your solution for the benefit of others.

    db
    Why do they call it rush hour when nothing moves? - Robin Williams

Similar Threads

  1. Replies: 2
    Last Post: 06-02-2012, 10:51 PM
  2. Replies: 6
    Last Post: 05-12-2012, 04:29 AM
  3. Inserting line into text file
    By Onra in forum Advanced Java
    Replies: 5
    Last Post: 09-14-2010, 11:21 AM
  4. Scanning text file and inserting contents into array
    By jmwalloh in forum New To Java
    Replies: 8
    Last Post: 03-24-2010, 12:33 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •