How to create a simple Java JFrame Window
Java JFrame Window is a top level component that defines the Lookandfeel of your application.Its from this window that we can add other elements like JButton , JTextField, JLabel etc.
This tutorial introduces you to JFrame class and some of the methods that it has.
Code to create simple Java JFrame Window
Run below code
Adding swing components to Java JFrame Window
Setting Java JFrame Window DefaultCloseOperation
There are several options that can be take by JFrame.setDefaultCloseOperationMethod.These are
- JFrame.EXIT_ON_CLOSE-This closes JFrame window completely.
- JFrame.DISPOSE_ON_CLOSE-Exits windows and destroy its object releasing all resources back.
- JFrame.DO_NOTHING_ON_CLOSE-when close button is clicked,nothing happens to the JFrame window.
- JFrame.HIDE_ON_CLOSE-does not destroy JFrame object but hides it.