Results 1 to 2 of 2
Thread: jLabel update
- 04-13-2012, 03:30 AM #1
Member
- Join Date
- Mar 2012
- Posts
- 18
- Rep Power
- 0
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
-
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
-
Problem about JLabel not update in JPanel
By fantasyme in forum Java AppletsReplies: 11Last Post: 10-16-2011, 07:00 AM -
jTabbedPane1StateChanged update the jLabel text from another class
By Jhovarie in forum AWT / SwingReplies: 6Last Post: 08-20-2011, 08:21 AM -
update a jlabel
By niba10 in forum AWT / SwingReplies: 3Last Post: 04-04-2011, 07:43 PM -
Update JLabel during loop automatically
By carnado2008 in forum AWT / SwingReplies: 4Last Post: 01-22-2011, 02:55 PM -
Jlabel update problem
By fantasyme in forum AWT / SwingReplies: 3Last Post: 04-14-2010, 05:10 AM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks