
- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
How to activate and deactivate JFrame in Java
Here, we are activating a frame. For deactivation, we have used dispose −
Thread.sleep(2000); frame.setVisible(false);
The frame first activates and then deactivates after 2 seconds since we have set sleep to 2000 miliseconds.
The following is an example to activate and deactivate JFrame −
Example
import java.awt.Frame; import javax.swing.JFrame; import javax.swing.JLabel; public class SwingDemo { public static void main(String[] args) throws InterruptedException { JFrame frame = new JFrame(); frame.add(new JLabel("Demo")); frame.pack(); frame.setVisible(true); Thread.sleep(2000); frame.setState(Frame.ICONIFIED); Thread.sleep(2000); frame.setVisible(false); frame.dispose(); System.exit(0); } }
The output is as follows displaying the frame −
Output
- Related Questions & Answers
- How to Capture a pick event and use it to activate or deactivate Line Plots in Matplotlib
- How to create a Titleless and Borderless JFrame in Java?
- How to maximize JFrame in Java Swing
- How to change JFrame background color in Java
- How to set FlowLayout for JFrame in Java?
- How to add background Image to JFrame in Java
- How to create JFrame with no border and title bar in Java?
- How to set default button for JFrame in Java?
- How to Deactivate or Delete Facebook Messenger
- How to activate virtualenv on Linux?
- How to disable close button on a JFrame in Java?
- How to deactivate scientific notation of numbers in R?
- What are the differences between JFrame and JDialog in Java?
- How to set minimum size limit for a JFrame in Java
- How to set location of JLabel in a JFrame with Java?
Advertisements