Results 1 to 5 of 5
  1. #1
    Alexis is offline Member
    Join Date
    Nov 2010
    Posts
    17
    Rep Power
    0

    Default how to set my frame in the middle of the screen

    Hello ! I am newbie in java !
    here is my example code
    Java Code:
    import java.awt.*;
    import javax.swing.*;
    import java.awt.event.*;
    
    public class showJFrame
    {
    	public static void main (String [] args)
    	{
    		JFrame fr=new JFrame("Swing Frame");
    		fr.setSize(800,600);
    		Container cp=fr.getContentPane();
    		FlowLayout l=new FlowLayout();
    		cp.setLayout(l);
    		fr.addWindowListener(new Close_Window());
    		fr.setVisible(true);
    	}
    }
    
    		
    class Close_Window extends WindowAdapter
    {
    	public void windowClosing(WindowEvent e)
    	{
    		System.exit(0);
    	}
    }
    I need the window starts in the middle of the screen

    what can i change/add ?
    Last edited by Eranga; 11-21-2010 at 10:23 AM. Reason: code tags added

  2. #2
    DarrylBurke's Avatar
    DarrylBurke is offline Forum Police
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,416
    Rep Power
    20

    Default

    Java Code:
    setLocationRelativeTo(null);
    db

  3. #3
    DarrylBurke's Avatar
    DarrylBurke is offline Forum Police
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,416
    Rep Power
    20

    Default

    And for what you are doing, there's no need for a window listener.
    Java Code:
    setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    db

  4. #4
    Alexis is offline Member
    Join Date
    Nov 2010
    Posts
    17
    Rep Power
    0

    Default

    Thank you very much for both of answers !!!!

  5. #5
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,372
    Blog Entries
    1
    Rep Power
    20

Similar Threads

  1. Find the Middle of a JFrame??
    By bdizzle in forum AWT / Swing
    Replies: 9
    Last Post: 02-21-2010, 08:39 PM
  2. Full Screen Frame Resolution Problem
    By Krooger in forum AWT / Swing
    Replies: 2
    Last Post: 11-24-2009, 11:05 PM
  3. Blank Screen while navigating from one screen to another
    By mohana.krishna in forum Java Servlet
    Replies: 0
    Last Post: 03-03-2009, 05:03 PM
  4. Prob. with screen resolution and Frame size??
    By SANDY_INDIA in forum AWT / Swing
    Replies: 1
    Last Post: 08-16-2008, 12:51 PM
  5. Return in the Middle of synchronized Block
    By ariak in forum Advanced Java
    Replies: 1
    Last Post: 07-26-2007, 10:24 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •