I am new to java and learning about swing and JFrames. I have followed multiple tutorials and I can not get my JFrame to stay open. When I run my code I can see the empty JFrame open, but it closes or disappears after about 2 seconds. This happens when I use IntelliJ and Eclipse. I have posted a sample of my code that should open a empty JFrame, but it always disappears after a few seconds. Could someone please help me stop it from closing?
Things I have tried to fix it.
- Reinstalled Java jdk-13.0.1
- Reinstalled IntelliJ and Eclipse
- Added jdk/bin directory to windows environment variables
Updated video card drivers
package com.FrameDemo; import javax.swing.*; public class EmptyJFrame { public static void main(String[] args) { JFrame frame = new JFrame(); frame.setSize(300, 300); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.setVisible(true); } }