Results 1 to 4 of 4
  1. #1
    flok is offline Member
    Join Date
    Sep 2009
    Location
    Gouda, the Netherlands
    Posts
    24
    Rep Power
    0

    Default netbeans: changing an object from within an action

    Hi,

    In netbeans I created a form with a button and a text-area.
    Now when I press the button I would like to do some calculations in the text-area.
    This works so far that the calculations-code is invoked but the form is only refreshed after the button-action-method is finished.
    I got a:
    Java Code:
       private javax.swing.JTextArea output;
    and from within:
    Java Code:
       private void jButton1MouseClicked(java.awt.event.MouseEvent evt) { }
    I call:
    Java Code:
       output.append("some text");
    And only after jButton1MouseClicked is finished, this text is shown in the form.
    How can I fix that? I tried to call repaint() after each output.append() but that didn't help.

  2. #2
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,315
    Blog Entries
    1
    Rep Power
    26

    Default

    You don't give enough information for anyone to know why you are having this problem. Perhaps you are tying up the EDT within your actionPerformed method, but without my crystal ball, I'm only guessing.

    Luckily my magic 8 ball still works, and it says: look at using a SwingWorker object.

    If this doesn't help, you may wish to provide more details and code, enough necessary to answer this question.

  3. #3
    flok is offline Member
    Join Date
    Sep 2009
    Location
    Gouda, the Netherlands
    Posts
    24
    Rep Power
    0

    Default

    Quote Originally Posted by Fubarable View Post
    You don't give enough information for anyone to know why you are having this problem. Perhaps you are tying up the EDT within your actionPerformed method, but without my crystal ball, I'm only guessing.
    Luckily my magic 8 ball still works, and it says: look at using a SwingWorker object.
    If this doesn't help, you may wish to provide more details and code, enough necessary to answer this question.
    Yes! The swingworker fixed it!
    Put my code as an anonymous class in the swingworker. Then from there it updates my textarea object.

    Thanks a lot!

  4. #4
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,315
    Blog Entries
    1
    Rep Power
    26

Similar Threads

  1. Replies: 2
    Last Post: 11-26-2010, 03:12 AM
  2. Replies: 1
    Last Post: 03-04-2009, 07:14 PM
  3. Replies: 1
    Last Post: 07-22-2008, 05:27 PM
  4. Replies: 1
    Last Post: 04-17-2008, 11:10 PM
  5. Creating object of Type Object class
    By venkatv in forum New To Java
    Replies: 3
    Last Post: 07-17-2007, 04:33 PM

Tags for this Thread

Posting Permissions

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