Home Java Example Java Swing Setting Bounds for a maximized frame
Questions:Ask|Latest


 
 

Share on Google+Share on Google+

Setting Bounds for a maximized frame

Advertisement
In this section, you will learn how to set the bounds for a maximized frame.

Setting Bounds for a maximized frame

     

In this section, you will learn how to set the bounds for a maximized frame. This means to fix the size for the frame after maximizing it.

This program sets the bounds for the maximized frame using setMaximizedBounds() method of the JFrame class. There has been shown the images below for the illustration:

Restored Frame:
Set Bound Frame before maximization (Size : 398*399)

Maximized Frame:
Set Bound Frame in maximized form (Size : 498*498)

Code description:

setMaximizedBounds():
This is the method of the JFrame class sets the bounds for a maximized frame. The method takes the object of Rectangle class to set the size of frame. Constructor of the Ractangle class takes four argument in sequence: row of the screen, column of the screen, width of the frame and last is the height of the frame. 

Here is the code of the program:

import java.awt.*;
import javax.swing.*;

public class SwingSetBounds{
  public static void main(String[] args){
  JFrame frame = new JFrame();
  Rectangle bounds = new Rectangle(00500500);
  frame.setMaximizedBounds(bounds);
  frame.setSize(400400);
  frame.setVisible(true);
  frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
  }
}

Download this example.

Advertisement

If you enjoyed this post then why not add us on Google+? Add us to your Circles



Liked it!  Share this Tutorial


Follow us on Twitter, or add us on Facebook or Google Plus to keep you updated with the recent trends of Java and other open source platforms.

Posted on: April 14, 2007

Ask Questions?    Discuss: Setting Bounds for a maximized frame  

Post your Comment


Your Name (*) :
Your Email :
Subject (*):
Your Comment (*):
  Reload Image
 
 
Comments
DMCA.com