Home | Ajax | BioInformatics | Dojo | EAI | EJB | Hibernate | J2ME | Java | Java Glossary | Java Servlets | JavaScript | Jboss | JDBC | JDO | Jmeter | JSF | JSP | JUnit | Maven | MySQL | Spring Framework | SQL | Struts | Technology | WAP | Web Services | XML
 
 
Search All Tutorials
  

 
Programming Tutorials: Ajax | Articles | JSP | Bioinformatics | Database | Free Books | Hibernate | J2EE | J2ME | Java | JavaScript | JDBC | JMS | Linux | MS Technology | PHP | RMI | Web-Services | Servlets | Struts | UML
 
Java
  JDO Tutorials
  EAI Articles
  Struts Tutorials
  Java Tutorials
  Java Certification
  Java Applet
Questions
Comments

Creating a Frame : Swing Tutorials

                         

This program shows you how to create a frame in Java Swing Application. The frame in java works like the main window where your components (controls) are added to develop an application. In the Java Swing, top-level windows are represented by the JFrame class. Java supports the look and feel and decoration for the frame. 

For creating java standalone application you must provide GUI for a user. The most common way of creating a frame is, using single argument constructor of the JFrame class. The argument of the constructor is the title of the window or frame. Other user interface are added by constructing and adding it to the container one by one. The frame initially are not visible and to make it visible the setVisible(true) function is called passing the boolean value true. The close button of the frame by default performs the hide operation for the JFrame. In this example we have changed this behavior to window close operation by setting the setDefaultCloseOperation() to EXIT_ON_CLOSE value.

setSize (400, 400):
Above method sets the size of the frame or window to width (400) and height (400) pixels.

setVisible(true):
Above method makes the window visible.

setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE):
Above code sets the operation of close operation to Exit the application using the System exit method.

Here is the code of the program : 

import javax.swing.*;

public class Swing_Create_Frame{
  public static void main(String[] args){
    JFrame frame = new JFrame("Frame in Java Swing");
    frame.setSize(400400);
    frame.setVisible(true);
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
  }
}

Download this example.

                         

Facing Programming Problem?
Add This Tutorial To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 

Current Comments

11 comments so far (post your own) View All Comments Latest 10 Comments:

1 ) how to declare the variable static and acess them.

2) how to send data from one frame to another.

Posted by sanjana on Wednesday, 04.30.08 @ 16:06pm | #58216

Regarding Has Map.

Posted by Ramesh on Saturday, 03.1.08 @ 14:59pm | #50843

i have created the GUI using netbeans.But when project is run only the main window is displayed and none of the components in it are shown.How to connect Main.java and NewJFrame1.java in netbeans?

Posted by ramya on Friday, 02.29.08 @ 23:30pm | #50762

how to divide a frame in swings if so provide me some examples as soon as possible and tell me the way to know the key words of swings

Posted by uma on Saturday, 02.16.08 @ 17:00pm | #48583

I have created a main frame with 2 buttons, New and Close All. When New is clicked, a new frame is to be created titled Frame 1. Subsequent clicks of New will create additional frames, Frame 2, Frame 3, etc. When Close All is clicked in my main frame, all Frame n's are to close. I'm new to Java Swing and cannot seem to find an example on how to perform this in code? I see stuff on internal frames, but that is not what I am attempting to do. Can you help?

Posted by J. Beaumont on Wednesday, 05.30.07 @ 07:50am | #17703

How to use HashMap with Swings to retrieve data from database

Posted by Ashish Kumar on Friday, 04.20.07 @ 15:50pm | #14623

Hi,
P.Rajeswari!
I receive your problem for creating menus in the frame. Don’t worry; Pease, click the following link and get the creation process and description to menus or submenus in the frame.

Create menus and submenus

Vinod kumar
(RoseIndia.net)

Posted by vinod kumar on Friday, 04.13.07 @ 18:02pm | #14108

i need more inforamtion to create menu in hte frames plz help me sir
regards
raji

Posted by P.Rajeswari on Friday, 03.30.07 @ 10:52am | #12970

Hi Anand,

You can get the solution of your problem on the following link. Please click at:

http://www.roseindia.net/java/example/java/swing/RemoveTitleFrame.shtml

Thanks
Chandan Kumar
Roseindia Team Member

Posted by Chandan Kumar on Sunday, 03.18.07 @ 18:18pm | #12111

How to create a freme with out title bar

Posted by Anand kumar on Sunday, 03.18.07 @ 11:25am | #12078

Leave your comment:

Name:

Email:

URL:

Title:

Comments:


Enter Code:

 

Note: Emails will not be visible or used in any way, and are not required. Please keep comments relevant. Any content deemed inappropriate or offensive may be edited and/or deleted.

No HTML code is allowed. Line breaks will be converted automatically. URLs will be auto-linked. Please use BBCode to format your text.

Hot Web Programming Job

Java String toLowerCase Example
Java String toCharArray Example
Java String substring Example
Java String indexOf Example
Java String startsWith Example
Java String hashCode Example
Java String matches Example
Java String length Example
Java String lastIndexOf Example
Java String isEmpty Example
Java String equalsIgnoreCase Example
Java String equals Example
Java String endsWith Example
Java String copyValueOf Example
Java String contentEquals Example
  EAI Articles
  Java Certification
Tell A Friend
Your Friend Name
Search Tutorials

 

 
 
Browse all Java Tutorials
Java JSP Struts Servlets Hibernate XML
Ajax JDBC EJB MySQL JavaScript JSF
Maven2 Tutorial JEE5 Tutorial Java Threading Tutorial Photoshop Tutorials Linux Technology
Technology Revolutions Eclipse Spring Tutorial Bioinformatics Tutorials Tools SQL
 

Home | JSP | EJB | JDBC | Java Servlets | WAP  | Free JSP Hosting  | Search Engine | News Archive | Jboss 3.0 tutorial | Free Linux CD's | Forum | Blogs

About Us | Advertising On RoseIndia.net  | Site Map

India News

Send your comments, Suggestions or Queries regarding this site at roseindia_net@yahoo.com.

Copyright © 2007. All rights reserved.