EDIT: Although I have never used (or even known about) SwingUtilities.InvokeLater()
before today, implementing it did not solve the problem. The 1-second delay between the visibility of the JFrame and the appearance of the JLabel remains with the following, updated code.
public class DelayTest {
public static void main(String [] args) {
new DelayTest();
}
public DelayTest() {
SwingUtilities.invokeLater(new Runnable()
{
public void run()
{
long start = System.currentTimeMillis();
JFrame frame = new JFrame("Demo");
Container content = frame.getContentPane();
//sizing
Dimension dimm = new Dimension(500, 200);
frame.setPreferredSize(dimm);
frame.setResizable(false);
//content
content.add(new JLabel("Hello, Delayed World"));
System.out.println("Added Label at: " +
(System.currentTimeMillis() - start) + " Milliseconds");
//end
frame.pack();
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setLocationRelativeTo(null);
frame.setVisible(true);
System.out.println("Finished execution at: " +
(System.currentTimeMillis() - start) + " Milliseconds");
}
});
}
}
I have, so far, done the following to try to resolve the error:
- Updated my Computer (Mac OS X 10.11.6)
- Updated Java (java version "1.8.0_111")
- Erased and Re-Installed Eclipse (Java Neon.2)
- Exported jar, just to see if the problem existed outside Eclipse
- Tested using SwingUtilities.InvokeLater() as seen above (Hopefully I used it correctly)
I restarted several times throughout the process but nothing seemed to fix it. I'm hoping you can either help me find the error in my code that is delaying the Label (which I don't think exists,) or verify that my code works on your computer.