Results 1 to 2 of 2

Thread: jLabel update

  1. #1
    Ericyue is offline Member
    Join Date
    Mar 2012
    Posts
    18
    Rep Power
    0

    Exclamation jLabel update

    hi ,

    i am doing a program which will display the image and refresh due to i have 100 image in my local machine. this is the example of my code


    import javax.swing.JLabel;
    import javax.swing.JFrame;
    import javax.swing.ImageIcon;
    import java.awt.Toolkit;

    public class Tester
    {
    public static void main(String[]args)
    {
    int i = 1;
    ImageIcon ii=new ImageIcon("1.jpeg");
    JLabel label=new JLabel(ii);
    JFrame frame=new JFrame("Put image on JLabel");
    frame.add(label);
    while(i<=100)
    {
    label.setIcon(new ImageIcon(i + "jpeg"));
    File f = new File(i + ".jpeg");
    f.rename("screenshot.jpeg");
    i++;
    }

    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOS E);

    frame.setSize(400,400);

    frame.setVisible(true);


    }
    }

    the image will start from 1.jped, 2.jpeg till 100.jpeg ... and i ll rename it to screenshot.jpeg so that it will override the image and also can save the harddisk space. it can compile with no problem but when i run the program , a frame will appear while nothing inside the frame . so , what is the problem of this ?? sorry for my ignorance and thanks for the reply

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

    Default Re: jLabel update

    Swing uses one thread and one thread alone to do all user interaction and drawing with -- including drawing of GUI components, and if you tie up this thread with long-running code, your GUI will become completely unresponsive. This thread is called the EDT or event dispatch thread, and to solve your problem, you're going to have to use a background thread to do your image reading with. For the details on how to solve this, lease have a look here: Concurrency in Swing.

Similar Threads

  1. Problem about JLabel not update in JPanel
    By fantasyme in forum Java Applets
    Replies: 11
    Last Post: 10-16-2011, 08:00 AM
  2. Replies: 6
    Last Post: 08-20-2011, 09:21 AM
  3. update a jlabel
    By niba10 in forum AWT / Swing
    Replies: 3
    Last Post: 04-04-2011, 08:43 PM
  4. Update JLabel during loop automatically
    By carnado2008 in forum AWT / Swing
    Replies: 4
    Last Post: 01-22-2011, 03:55 PM
  5. Jlabel update problem
    By fantasyme in forum AWT / Swing
    Replies: 3
    Last Post: 04-14-2010, 06:10 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
  •