- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- 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 can we minimize/maximize a JFrame programmatically in Java?
A JFrame class is a subclass of Frame class and the components added to a frame are referred to as its contents, these are managed by the contentPane. A JFrame contains a window with title, border, (optional) menu bar and user-specific components. By default, we can minimize a JFrame by clicking on minimize button and maximize a JFrame by clicking on maximize button at the top-right position of the screen. We can also do programmatically by using setState(JFrame.ICONIFIED) to minimize a JFrame and setState(JFrame.MAXIMIZED_BOTH) to maximize a JFrame.
Example
import java.awt.*; import java.awt.event.*; import javax.swing.*; public class JFrameIconifiedTest extends JFrame implements ActionListener { private JButton iconifyButton, maximizeButton; public JFrameIconifiedTest() { setTitle("JFrameIconified Test"); iconifyButton = new JButton("JFrame Iconified"); add(iconifyButton, BorderLayout.NORTH); iconifyButton.addActionListener(this); maximizeButton = new JButton("JFrame Maximized"); add(maximizeButton, BorderLayout.SOUTH); maximizeButton.addActionListener(this); setSize(400, 275); setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); setLocationRelativeTo(null); setVisible(true); } public void actionPerformed(ActionEvent ae) { if(ae.getSource().equals(iconifyButton)) { setState(JFrame.ICONIFIED); // To minimize a frame } else if(ae.getSource().equals(maximizeButton)) { setExtendedState(JFrame.MAXIMIZED_BOTH); // To maximize a frame } } public static void main(String args[]) { new JFrameIconifiedTest(); } }
Output
In the above program, if we click on "JFrame Iconified" button, the frame is minimized and click on "JFrame Maximized" button, the frame is maximized.
- Related Articles
- How can we disable the maximize button of a JFrame in Java?
- How to maximize JFrame in Java Swing
- Removing minimize/maximize buttons in Tkinter
- How can we hide left/right pane of a JSplitPane programmatically in Java?
- How to maximize and minimize browsers in Selenium with python?
- How can we switch off an Android phone programmatically?
- I want to resize and position a JFrame in Java. How can I achieve that?
- How to disable close button on a JFrame in Java?
- How to create a Titleless and Borderless JFrame in Java?
- How to activate and deactivate JFrame in Java
- How to change JFrame background color in Java
- How to set FlowLayout for JFrame in Java?
- How can we implement a JToggleButton in Java?
- How can we filter a JTable in Java?
- How can we stop a thread in Java?

Advertisements