Results 1 to 2 of 2
  1. #1
    hoglu is offline Member
    Join Date
    Dec 2008
    Posts
    1
    Rep Power
    0

    Default JTextArea Animation

    Hi all. This is my first post, hope to find good time here :)

    It looks simple problem, but took me a few hours and still i didn't get solution.
    I want to add string to JTextArea like animation. For example, i tried adding numbers like, while Frame is running, it appends automatically numbers. When it adds number then wait mseconds then refresh and adding another number.

    It is basic structure code, i tried to use. I also tried Timer and ActionListiner but i didn't do that. This program supposed to generating numbers to TextArea like animation, and waiting per number. Could you help me with this code? Thaks alot :confused:

    Java Code:
    import java.awt.*;
    import javax.swing.*;
    import java.awt.event.*;
    
     
    
      public class TextAreaAnimation extends JFrame {
    
        public TextAreaAnimation() {
            
            super ("Text Area Animation");
            setLayout(new FlowLayout());
            
            JTextArea textArea=new JTextArea(10, 10);
            textArea.setEditable(false);
            add(textArea);
            try {
                for (Integer i = 0; i <100; i++) {
                    textArea.append(i.toString()+"\n");
                    Thread.sleep(200);
                    textArea.repaint();
                    
                    
                }
            } catch (Exception e) {
            }
            
        }

  2. #2
    DarrylBurke's Avatar
    DarrylBurke is offline Forum Police
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,457
    Rep Power
    20

    Default

    Never call sleep() on the EDT (unless the purpose is to freeze the GUI).

    I think you'll find all the guidance you need here:
    Lesson: Concurrency in Swing (The Java™ Tutorials > Creating a GUI with JFC/Swing)

    db

Similar Threads

  1. Animation Synchronization
    By dreadrocksean in forum Advanced Java
    Replies: 5
    Last Post: 08-08-2008, 03:56 AM
  2. Text animation
    By Java Tip in forum java.awt
    Replies: 0
    Last Post: 06-21-2008, 09:44 PM
  3. How to create animation
    By Java Tip in forum java.awt
    Replies: 0
    Last Post: 06-21-2008, 09:43 PM
  4. GUI Animation
    By serfster in forum New To Java
    Replies: 2
    Last Post: 06-11-2008, 04:37 AM
  5. GridLayout with animation?
    By tojas in forum AWT / Swing
    Replies: 3
    Last Post: 11-12-2007, 11:16 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
  •