Place the JFrame on middle of the screen

I want to place a JFrame on middle of the screen on any resolution. Using setBounds not work for all, I need a relative way to do this. What's the easiest way to do this?

I've read the doc lol. But unable to find the best, that's why I ask here.
setLocationRelativeTo() not set the frame in the middle of the screen, it's set the upper left corner of the frame into the middle.

Similar Messages

  • How to place the JFrame in center of the screen

    Hi.. please any one tell me how to place the jframe in the center of the screen.. i am working on windows.
    setLocationByPlotform is not working...

    //GETS SCREEN SIZE
            Dimension screen_Dimension =Toolkit.getDefaultToolkit ().getScreenSize ();
            //GETS WINDOWS SIZE
            Dimension frame_Dimension = window.getSize ();
            //PUTS FRAME IN THE "MIDDLE" OF THE SCREEN
            window.setLocation ( new Point (
                    (screen_Dimension.width / 2-frame_Dimension.width / 2),
                    (screen_Dimension.height / 2-frame_Dimension.height/ 2)));Not sure if you want the raw version of it.......

  • How to print the JFrame In The Center Of The Page?

    hi there in the following code iam trying to print a JFrame
    but the frame appear in the printed page at the top left
    and i want it to appear in the top center of the page
    how to do that?
    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.*;
    import java.awt.print.*;
    class PrintUIWindow implements Printable, ActionListener {
        JFrame frameToPrint;
        public int print(Graphics g, PageFormat pf, int page) throws
                                                            PrinterException {
            if (page > 0) {
                return NO_SUCH_PAGE;
            Graphics2D g2d = (Graphics2D)g;
            g2d.translate(pf.getImageableX(), pf.getImageableY()-55);
            frameToPrint.print(g);
            return PAGE_EXISTS;
        public void actionPerformed(ActionEvent e) {
             PrinterJob job = PrinterJob.getPrinterJob();
             job.setPrintable(this);
             boolean ok = job.printDialog();
             if (ok) {
                 try {
                      job.print();
                 } catch (PrinterException ex) {
        public PrintUIWindow(JFrame f) {
            frameToPrint = f;
        public static void main(String args[]) {
            UIManager.put("swing.boldMetal", Boolean.FALSE);
            JFrame f = new JFrame("Print UI Example");
            f.addWindowListener(new WindowAdapter() {
               public void windowClosing(WindowEvent e) {System.exit(0);}
            JLabel label1=new JLabel("Selling Bill",JLabel.CENTER);
            JLabel label2=new JLabel("Customer Name :Mahmoud Saleh       ",JLabel.LEFT);
            JLabel label3=new JLabel("Buying Date :29/8/2008             ",JLabel.LEFT);
            JLabel label4=new JLabel("Book Buyed :Java Printing          ",JLabel.LEFT);
            JLabel label5=new JLabel("Number : 6 Copies                  ",JLabel.LEFT);
            JLabel label6=new JLabel("Total Price :600 $                 ",JLabel.LEFT);
            label1.setFont(new Font("Courier New", Font.BOLD, 13));
            label2.setFont(new Font("Courier New", Font.BOLD, 13));
            label3.setFont(new Font("Courier New", Font.BOLD, 13));
            label4.setFont(new Font("Courier New", Font.BOLD, 13));
            label5.setFont(new Font("Courier New", Font.BOLD, 13));
            label6.setFont(new Font("Courier New", Font.BOLD, 13));
            JButton printButton = new JButton("Print This Window");
            printButton.addActionListener(new PrintUIWindow(f));               
            JPanel panel=new JPanel();
            panel.setLayout(new GridLayout(6,1));
            panel.add(label1);
            panel.add(label2);
            panel.add(label3);
            panel.add(label4);
            panel.add(label5);
            panel.add(label6);
            f.setSize(300,300);       
            f.setLocationRelativeTo(null);       
            f.add(panel,BorderLayout.CENTER);
            f.add(printButton,BorderLayout.SOUTH);
            panel.setBackground(Color.WHITE);
            f.setResizable(false);
            f.setVisible(true);
    }

    First_knight wrote:
    please tell me am i thinking right
    about this method: setImageableArea(.....)
    public void setImageableArea(double x, double y,  double width, double height);
    like I said, I've tried this method and it doesn't seem to do anything.
    the width=the JFrame Width,the height=the JFrame Height right?actually, when printing, 72 points (printing version of pixels) = 1 inch, so to do WYSIWYG, you need width = JFrameWidth * 72.0 / Toolkit.getToolkit().getScreenResolution. Ditto with height
    upper left beginningx(0)---------------------------200--------------------------------600-----------------------------------y(1000)upper right beginningyou need to do something like PageSetup.getImageableX and do Graphics.translate(x,y);
    also, if your page width = 720, that = 10 inches - that's a wide page (unless its in landscape)
    so if i want the JFrame To Be In The Center Of The Page I Would Choose From x=200 ,y=600 depending that frame width is 400Actually, it would be 300 - 700 in your example
    Because when i tried to use:setImageableArea(200, 600,  400, 200);like the above code
    no changes occurs in the printed paperYes. You need to offset the Graphics object

  • How to resize the components in a JFrame when the JFrame Resizes?

    Hi all,
    i have some problems with my app. I have set the JFrame resizable and that works fine for the JFrame but not for the components in the JFrame.
    So my question is how can i set the components in a JFrame to resize automatically when the JFrame resizes?
    Here are the important things from my code,...if you need more, just let me know, its my first post in a forum .
    Its a JFrame with a JTabbedPane and on the Tabs are Panels with buttons and Tables.
    Thank you in advance!
    public class MainMonitor extends JFrame {
    public MainMonitor() {
              super();
              initialize();
              setVisible(true);
         private void initialize() {
              this.setSize(1145, 785);
              this.setIconImage(Toolkit.getDefaultToolkit().getImage("Images/c.gif"));
              this.setContentPane(getJContentPane());
              this.setTitle("Company Manager");
              this.setResizable(true);
              this.setLocationRelativeTo(null);
         private JPanel getJContentPane() {
              if (jContentPane == null) {
                   jContentPane = new JPanel();
                   jContentPane.setLayout(null);
                   jContentPane.setOpaque(true);
                   jContentPane.add(getJTabbedPane(), null);
                   jContentPane.add(getJPanel11(), null);
              return jContentPane;
         private JTabbedPane getJTabbedPane() {
              if (jTabbedPane == null) {
                   jTabbedPane = new JTabbedPane();
                   jTabbedPane.setLocation(new Point(6, 69));
                   jTabbedPane.setSize(new Dimension(1120, 684));
                   jTabbedPane.addTab("P", null, getJPanel(), null);
                   jTabbedPane.addTab("K", null, getJPanel1(), null);
                   jTabbedPane.addTab("B", null, getJPanel2(), null);
              return jTabbedPane;
         

    Giasaste wrote:
    Thanks a lot, i didnt knew that the Layout Manager is a must.It's not a must, but it is the way to allow your app to be resized nicely and makes it much easier to maintain and enhance your program. Imagine creating a complex gui then later decide that you want another radiobutton and to remove a jlabel / jtextfield pair. with layout managers a chore becomes easy.

  • How can I make a JFrame pop up in the middle of the screen?

    On my application I have a help button. The button is used to trigger a pop up JFrame containing my help messages. This JFrame keeps popping up at the top left corner of my screen. Is there a way to make it pop up in the middle of the screen? Anyone?

    hi, try this:
    public static void centerWindow(Window win){
    Dimension screenSizeWithSpeedBar = Toolkit.getDefaultToolkit().getScreenSize();
    Dimension screenSize = new Dimension(screenSizeWithSpeedBar.width,screenSizeWithSpeedBar.height-25);
    Dimension frameSize = win.getSize();
    if (frameSize.height > screenSize.height)
    frameSize.height = screenSize.height;
    if (frameSize.width > screenSize.width)
    frameSize.width = screenSize.width;
    win.setSize(frameSize);
    win.setLocation((screenSize.width - frameSize.width) / 2, (screenSize.height - frameSize.height) / 2);
    It works with following arguments: JWindow, JFrame and JDialog

  • How do I make a JFrame appear in the middle of the screen

    When I use the setVisible method on a GUI (object which extends JFrame), it always pops up in the top left corner of the screen. What can I do to center it in the middle?

            Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
            setBounds((screenSize.width-400)/2, (screenSize.height-300)/2, 400, 300);

  • Help with centralising a box in the absolute middle og the browser screen

    Hello there, i was wondering if someone could help me out
    with a little problem im having.
    im trying to design a site which basically has a box in the
    middle of the browser where all the info is displayed.
    now i know that if u set the horizontal alignment to middle
    then the box will be in the middle of the screen, this much is fine
    However, my problem comes when u try to make it the centre of
    the vertical axis. i can place it a certain distance from the top
    to give it this impression of being in the middle, however if u
    view it from a higher screen size then it will no longer be in the
    middle vertically.
    ive tried setting the vertical alignment to middle but
    dreamweaver ignores that. it seems to be totally blind to the
    height of the screen, as when i have tried to put things at the
    bottom of the screen by making a table 100% tall it just ignores
    the height and these things that should be at the bottom are
    actually in the middle of the page.
    Could someone shed some light on this apparent shadow of
    dreamweaver as its been buggin me for a while now
    Cheers

    http://www.apptools.com/examples/tableheight.php
    Murray --- ICQ 71997575
    Adobe Community Expert
    (If you *MUST* email me, don't LAUGH when you do so!)
    ==================
    http://www.dreamweavermx-templates.com
    - Template Triage!
    http://www.projectseven.com/go
    - DW FAQs, Tutorials & Resources
    http://www.dwfaq.com - DW FAQs,
    Tutorials & Resources
    http://www.macromedia.com/support/search/
    - Macromedia (MM) Technotes
    ==================
    "The Scribe" <[email protected]> wrote in
    message
    news:eji5vg$992$[email protected]..
    > Hello there, i was wondering if someone could help me
    out with a little
    > problem
    > im having.
    >
    > im trying to design a site which basically has a box in
    the middle of the
    > browser where all the info is displayed.
    > now i know that if u set the horizontal alignment to
    middle then the box
    > will
    > be in the middle of the screen, this much is fine
    > However, my problem comes when u try to make it the
    centre of the vertical
    > axis. i can place it a certain distance from the top to
    give it this
    > impression
    > of being in the middle, however if u view it from a
    higher screen size
    > then it
    > will no longer be in the middle vertically.
    >
    > ive tried setting the vertical alignment to middle but
    dreamweaver ignores
    > that. it seems to be totally blind to the height of the
    screen, as when i
    > have
    > tried to put things at the bottom of the screen by
    making a table 100%
    > tall it
    > just ignores the height and these things that should be
    at the bottom are
    > actually in the middle of the page.
    >
    > Could someone shed some light on this apparent shadow of
    dreamweaver as
    > its
    > been buggin me for a while now
    > Cheers
    >

  • How to display the GUI that we developed, at middle of monitor screen

    I want to display my GUI at middle of monitor screen
    display = new JTextArea(5,20);
              JScrollPane scroller = new JScrollPane(display);
              getContentPane().add(scroller, BorderLayout.SOUTH);
              getContentPane().add(gui);
              pack();
              setSize(300,250);
              show();

    JFrame.setLocationRelativeTo()
    It centers the window if the argument passed to it is null.

  • HT5055 Just updated to lion and my cctv access has stopped functioning all I get is a white screen in the middle of the control panel where the camera shots should be.  I think it is caused by JAVA but am confused as when i view on snow leopard it works 

    Just updated to lion and my cctv access has stopped functioning all I get is a white screen in the middle of the control panel where the camera shots should be.  I think it is caused by JAVA but am confused as when i view on snow leopard it works  can you help

    Open "Java Preferences" either from spotlight or your utilities folder...it's probably going to say you need to install a java runtime. Then just click install!

  • How do I restore my Ipad 4 from my desktop computer? My charger was broken. I bought a new one but now it won't charge. I have a BATTERY bar in the middle of the screen that is flashing RED and I have a symbol on the bottom that looks like a charger.

    How do I restore my Ipad 4 from my desktop computer? My charger was damaged so I bought a new one but it won't charge. On my Ipad, I have a BATTERY bar in the middle that is flashing RED and an icon on the bottom that looks like the end of a charger. I have tried to force into reset mode, by holding the sleep key and home button SEVERAL times but it does NOT work. I have plugged my Ipad into my desktop computer, but I do not have a screen on my desktop that is coming up. THIS HAPPENED BEFORE AFTER I DID AN UPDATE AND WAS LOCKED OUT AND I USED EITHER ICLOUD OR ITUNES TO RESTORE, NOT SURE WHICH AND I FORGOT HOW.

    Hi MrsMoosie,
    I'm sorry to hear you are having these issues with your iPad. If your iPad isn't responding or doesn't appear to be charging, you may find the information and troubleshooting steps outlined in the following articles helpful, in particular the following portion:
    If you don't see the charging screen within an hour, or you see the connect to power screen, check your connector, USB cable, and power adapter. Make sure that everything is plugged in firmly, free of debris, and not damaged. You might want to try a different USB cable or power adapter.
    If your iPhone, iPad, or iPod touch doesn't respond or doesn't turn on - Apple Support
    If you can’t charge your iPhone, iPad, or iPod touch - Apple Support
    Regards,
    - Brenden

  • How can i get rid of the small box in the middle of my screen

    How do i go about getting rid of the box in the middle of my screen that offers stuff like webify and to sign up to you guys. i really hate that box being there.
    one more question " how do i go about getting the rid of the restore session box everytime i close my home page, i dont want to restore at times i just want to close my home page and when i open it up be at my home page.

    Ok, I fixed it, thank you but I still have another question I set google to be my main screen but now I have about 3 search bars one in the middle of the screen and to on top. My question to you is how can I get rid of the middle search bar on the google screen and just have the two on top?

  • I have an iPad 2 and the volume icon is in the middle of my screen and when i try to turn the volume down it just goes back up again and it  makes it impossible for me to play games

    i have an iPad 2 and the volume icon is in the middle of my screen and when i try to turn the volume down it just goes back up again and it  makes it impossible for me to play games or do anything

    Have you tried giving it a reset? Hold down the sleep and home keys for about 20 seconds. When you see the silver apple let go and let it reboot and see if htat helps.

  • When I try to open a picture from email all I get is a yellow mozilla square in the middle of my screen and it won't go away unless I restart and I can't view the picture.

    Why can't I open pictures sent to me in email. All I get is a yellow mozilla box in the middle of my screen that won't go away unless I restart.
    == This happened ==
    A few times a week
    == when I try to view a picture

    The ! turns up when iPhoto loses the connection between the thumbnail in the iPhoto Window and the file it represents.
    What version of iPhoto? Assuming 09 or later...
    Option 1
    Back Up and try rebuild the library: hold down the command and option (or alt) keys while launching iPhoto. Use the resulting dialogue to rebuild. Choose to Rebuild iPhoto Library Database from automatic backup.
    If that fails:
    Option 2
    Download iPhoto Library Manager and use its rebuild function. This will create a new library based on data in the albumdata.xml file. Not everything will be brought over - no slideshows, books or calendars, for instance - but it should get all your albums and keywords back.
    Because this process creates an entirely new library and leaves your old one untouched, it is non-destructive, and if you're not happy with the results you can simply return to your old one. .
    Regards
    TD

  • Is there a way to force my iPad to shut down? I "slid" to turn off three hours ago. The "wheel" is still spinning in the middle of the screen.

    Is there a way to force my iPad to shut down? I "slid" to turn off three hours ago. The "wheel" is still spinning in the middle of the screen.

    Yeah, hold down the top Sleep button and the Home button simultaneously.  Continue to hold until the screen goes blank and the Apple logo appears.  Ignore the red slider midway through this process, just keep holding both buttons down until the Apple logo appears -- it takes about 8-10 seconds.  That should do a soft reset and fix your problem.

  • I need some advice on replacing my ipod touch 4th generation screen. The silver plate won't go back into it's original place and i can't put the screws back in. I really need help i don't want my ipod to be broken!!!

    I started to replace my ipod 4g screen but the silver plate that goes on top of the battery won't go back into place. It's not lining up with the screw holes so i can't finish the repair. Please I'm begging you all to help me with some advice and tips!!!!!!!!!!!!!! It will be greatly appreeciated. ASAP

    Your best bet is to email the company that sold you the screen for advice.  Or you could search on YouTube for repair instructions.  Hopefully, you will see where you went wrong.  Apple will not do an out-of-warranty replacement on an iPod that has been opened.

Maybe you are looking for

  • VLD-6328 error : Use a flat file as Source in a mapping in OWB 10.2

    Dear all, I have created a simple mapping using a flat file in a remote server as a source and a simple table as a target. When I try to validate the mapping I get the following warning: "VLD-2398: No data file specified. Generated code will use the

  • I'm using 10.6.8 and upgraded facetime to 1.0.4 and now it won't work 1

    Facetime kept saying it was connecting then hanging up so I looked to see if there was an update from my version and there was. I upgraded to 1.0.4 and now it says "Could not sign in. Please check your network connection and try again." I have sent i

  • Serial number creation

    Hi I want to create serial number for final product and its 2 sub assemblies in SAP after quality inspection. And these 3 parts should have a link for traceability. Is this possible In standard. Janardhanan

  • Video on particular websites does not play.

    Video doesn't play on sites like Fox.Com. I don't get a warning, pop up or the like. They do, however, play on Maxthon and other browsers. I cleared by cache, reinstalled and all the other typical hullabaloo to no avail.

  • Messages not appearing on mac with mountain lion.

    I downloaded ML and have an iphone 4 with up to date OS software. Is there a reason that my messages are not appearing on both? I have enabled messages on both devices, but nothing is transferring over. In fact I think that some imessages are not com