Results 1 to 5 of 5
- 11-21-2010, 09:46 AM #1
Member
- Join Date
- Nov 2010
- Posts
- 17
- Rep Power
- 0
how to set my frame in the middle of the screen
Hello ! I am newbie in java !
here is my example code
I need the window starts in the middle of the screenJava 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); } }
what can i change/add ?Last edited by Eranga; 11-21-2010 at 10:23 AM. Reason: code tags added
- 11-21-2010, 10:10 AM #2
dbJava Code:setLocationRelativeTo(null);
- 11-21-2010, 10:11 AM #3
And for what you are doing, there's no need for a window listener.
dbJava Code:setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
- 11-21-2010, 10:17 AM #4
Member
- Join Date
- Nov 2010
- Posts
- 17
- Rep Power
- 0
Thank you very much for both of answers !!!!
- 11-21-2010, 10:23 AM #5
- Join Date
- Jul 2007
- Location
- Colombo, Sri Lanka
- Posts
- 11,374
- Blog Entries
- 1
- Rep Power
- 18
@OP, please use code tags no quote tags. ;)
Similar Threads
-
Find the Middle of a JFrame??
By bdizzle in forum AWT / SwingReplies: 9Last Post: 02-21-2010, 08:39 PM -
Full Screen Frame Resolution Problem
By Krooger in forum AWT / SwingReplies: 2Last Post: 11-24-2009, 11:05 PM -
Blank Screen while navigating from one screen to another
By mohana.krishna in forum Java ServletReplies: 0Last Post: 03-03-2009, 05:03 PM -
Prob. with screen resolution and Frame size??
By SANDY_INDIA in forum AWT / SwingReplies: 1Last Post: 08-16-2008, 12:51 PM -
Return in the Middle of synchronized Block
By ariak in forum Advanced JavaReplies: 1Last Post: 07-26-2007, 10:24 AM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks