Results 1 to 7 of 7
Like Tree1Likes
  • 1 Post By DarrylBurke

Thread: Deadlock with DocumentListener

  1. #1
    dsharma is offline Member
    Join Date
    Apr 2012
    Posts
    5
    Rep Power
    0

    Default Deadlock with DocumentListener

    Quote Originally Posted by camickr View Post
    You need to wrap your code in the DocumentListener in a SwingUtilities.invokeLater(...). This will add the code to the end of the EDT so that it executes after the Document has been completely updated.

    Hi,
    I was also facing the same problem when i was using documentListener and trying to change the value of text feild. But after using SwingUtilities.invokeLater it got resolved. But after changing the text the focus is getting lost. It is going into deadlock state as there is a synchonous lock that is with document and calling setText() JtextFeild is trying to get the lock so that's y it is going in deadlock state.


    Can you please tell me how can i change the value of text feild using documentListener

  2. #2
    DarrylBurke's Avatar
    DarrylBurke is offline Member
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,244
    Rep Power
    19

    Default Re: Deadlock with DocumentListener

    When you have a question, start your own thread -- they're free. Don't resurrect an old thread and don't add an unrelated question in another poster's thread.

    Removed from http://www.java-forums.org/new-java/...textfield.html

    db
    If you're forever cleaning cobwebs, it's time to get rid of the spiders.

  3. #3
    DarrylBurke's Avatar
    DarrylBurke is offline Member
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,244
    Rep Power
    19

    Default Re: Deadlock with DocumentListener

    You need to respect Swing's single threaded rule. Note that many Swing methods which are, up to Java SE 6, documented as being thread-safe are in fact not thread-safe. This has been recognized and the documentation has been corrected in Java SE 7.

    All Swing constructors and methods, with the possible exception of repaint(), should be called only on the EDT.

    db
    dsharma likes this.
    If you're forever cleaning cobwebs, it's time to get rid of the spiders.

  4. #4
    dsharma is offline Member
    Join Date
    Apr 2012
    Posts
    5
    Rep Power
    0

    Default Re: Deadlock with DocumentListener

    So is there any way to change the value of text feild using document listener during document event?

  5. #5
    DarrylBurke's Avatar
    DarrylBurke is offline Member
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,244
    Rep Power
    19

    Default Re: Deadlock with DocumentListener

    You use a DocumentFilter, not a DocumentListener for that.

    db
    If you're forever cleaning cobwebs, it's time to get rid of the spiders.

  6. #6
    dsharma is offline Member
    Join Date
    Apr 2012
    Posts
    5
    Rep Power
    0

    Default Re: Deadlock with DocumentListener

    Quote Originally Posted by DarrylBurke View Post
    You use a DocumentFilter, not a DocumentListener for that.

    db
    I have to validate the value of text field lik it will not take any more than its maximum limit that has already defined and my class is implementing the DocumentListener.

    HOw can i acheive this senerio?

  7. #7
    DarrylBurke's Avatar
    DarrylBurke is offline Member
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,244
    Rep Power
    19

Similar Threads

  1. DocumentListener, KeyListener or a third option?
    By Muskar in forum New To Java
    Replies: 6
    Last Post: 11-20-2010, 11:58 PM
  2. Compiler deadlock
    By Arnold in forum New To Java
    Replies: 2
    Last Post: 06-27-2010, 12:57 PM
  3. Replies: 3
    Last Post: 05-28-2010, 04:18 AM
  4. [SOLVED] Deadlock ?
    By jon80 in forum New To Java
    Replies: 1
    Last Post: 06-14-2009, 07:54 PM
  5. Thread Deadlock
    By ajeeb in forum New To Java
    Replies: 2
    Last Post: 01-16-2009, 02:49 AM

Posting Permissions

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