Hi guys I've been having this problem lately with an image I added to my panel. Whenever I compile and run my program the image sometimes appear on screen but most of the time it doesn't. I really don't know what's going on so I would really appreciate the help
*The dimension of the image is 500x256
import javax.swing.*; import java.awt.event.*; import java.awt.*; public class GameMainZombie { public static void main(String[] args) { GameMainZombieGUI(); } public static void GameMainZombieGUI() { try { final JFrame pageMain = new JFrame("ZOMBIE GAME"); pageMain.setVisible(true); pageMain.setSize(500,600); pageMain.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); JPanel panel = new JPanel((LayoutManager) new GridBagLayout()); pageMain.getContentPane().add(panel, BorderLayout.CENTER); GridBagConstraints c = new GridBagConstraints(); JButton Start = new JButton("START GAME"); Start.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { GameLocationGUI(); pageMain.setVisible(false); } }); c.gridx = 0; c.gridy = 1; c.insets = new Insets(10,10,10,10); panel.add(Start, c); ImageIcon image = new ImageIcon("Zombies.jpg"); JLabel main = new JLabel(image); c.gridx = 0; c.gridy = 0; panel.add(main, c); }catch(Exception e) {} }