I want to show a buffered image in a JFrame
. I though the image should appear as soon as I do frame.setVisible(true)
. However, this is not true if I have, for instance, a Thread.sleep()
or another process after this command.
Is it possible to "force" to show the JFrame
content?
I'm calling this JFrame
when I click from a button in another (main) JFrame
. Below an example using a JPanel
instead of an image.
private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
JFrame f = new JFrame();
f.setLayout(new BorderLayout());
final JPanel p = new JPanel();
p.add(new JLabel("A Panel"));
f.add(p, BorderLayout.CENTER);
f.pack();
f.setVisible(true);
try {
Thread.sleep(5000);
} catch (InterruptedException ex) {
Logger.getLogger(NovoJFrame.class.getName()).log(Level.SEVERE, null, ex);
}
}