Hello Guys,
Bit stuck here I'm trying to loop through a JLabel and change the label after sleeping for a second, the sleep is working fine but the JLable won't change it just stays static.
Thanks
here is my code replicated with the same problem
import javax.swing.*; import java.awt.*; public class JpanelTest { public static void main(String[] args){ try{ Thread myThread = new Thread(); JFrame frame = new JFrame(); frame.setSize(300,300); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.setVisible(true); Container contain = frame.getContentPane(); JPanel panel = new JPanel(); frame.add(panel); for(int i = 1; i < 6; i++){ JLabel label = new JLabel("File number " + i + " is loaded"); panel.add(label); myThread.sleep(1000); contain.add(panel); System.out.println("1 + " + i); } } catch(InterruptedException e) { } } }
I want it to look like "File number 1 is loaded"
then clears and "File number 2 is loaded" etc
Thanks