How to centre a JFrame on the screen?

hi,
i'm just wondering how i could place a JFrame at the centre of the screen when i run the application?
thank you very much!

something like this should do it:
     int ix, iy;
     Dimension d = Toolkit.getDefaultToolkit().getScreenSize();
     Dimension dd = getSize();
     ix = (d.width-dd.width)/2;
     iy = (d.height-dd.height)/2;
     if(iy < 10) iy = 10;
     if(ix < 10) ix = 10;
     setLocation(ix,iy);If you have 1.4 then there are some additional stuff like the start menu on Windows that you might want to deal with.
Mark.

Similar Messages

  • Resizing and/or Moving the JFrame on the Screen

    Is there any way to resize a JFrame when the undecorated property is set to true.
    I would like to have a JFrame that is both undecorated and resizable.
    Similarly, I was also wondering how to move the JFrame on the screen if the
    undecorated property is set to true since there is not Border to select the
    JFrame to initiate the Move.
    Thanks!

    yes... setSize(), setLocation().
    And if you want the user to be able to do it with the mouse, you need to add a border to the rootpane to prevent anyone adding things over the whole rootpane, and add a mouse listener to it to catch mouse click and drag events and do the calculations.
    If you look at the BasicInternalFrameUI, or some thing in there should have some code that does the same thing.

  • Move a JFrame over the screen by specifying coordinates

    Hi,
    I have a JPanel within a JFrame.
    All I wanted to do is this. I have an image loaded in that JPanel
    using MediaTracker. I can move that image anywhere inside the JPanel.
    Now ,I want to "simulate" what is happening within this JPanel in the
    entire Screen. That is, whenvever I move the image inside the JPanel,
    there should be a (different) JFrame application on the screen and it should move according to the "relative" screen coordinates.
    I thought I could use SwingUtilities.convertPointToScreen()
    function , but really dont know how to proceed exactly.ie., how to
    move a JFrame application anywhere in the screen not manually but
    moving it based on the relative coordinates I retrieve from the JPanel.
    The "simulation" here is that a JFrame in the screen
    is equated to an image in a JPanel.
    Any help would be REALLY appretiated.
    Thanks,
    Pullu

    Don't know what you're really looking for, but try:
    Rectangle parentRect=SwingUtilities.getRoot(myJPanel).getBounds();
    and see if it gives you the info you need.
    ;o)
    V.V.

  • Locking a JFrame in the screen

    Help!!!!!, How can i lock a JFrame in the screen???
    I mean, no matter what others applications are open (or start the user after my java app) my frame will be at the front of all always.

    thats what I though too, but I has never done that.
    Do you know where could i find some documentation or code examples of programs than manipulate the OS in java???

  • How do i fix my itouch. the screen is black but it still responds to touch

    How do i fix my itouch. the screen is black but it still responds to touch

    First, try a system reset.  It cures many ills and it's quick, easy and harmless...
    Hold down the on/off switch and the Home button simultaneously until the screen blacks out or you see the Apple logo.  Ignore the "Slide to power off" text if it appears.  You will not lose any apps, data, music, movies, settings, etc.
    If the Reset doesn't work, try a Restore.  Note that it's nowhere near as quick as a Reset.  Connect via cable to the computer that you use for sync.  From iTunes, select the iPad/iPod and then select the Summary tab.  Follow directions for Restore and be sure to say "yes" to the backup.  You will be warned that all data (apps, music, movies, etc.) will be erased but, as the Restore finishes, you will be asked if you wish the contents of the backup to be copied to the iPad/iPod.  Again, say "yes."
    At the end of the basic Restore, you will be asked if you wish to sync the iPad/iPod.  As before, say "yes."  Note that that sync selection will disappear and the Restore will end if you do not respond within a reasonable time.  If that happens, only the apps that are part of the IOS will appear on your device.  Corrective action is simple -  choose manual "Sync" from the bottom right of iTunes.
    If you're unable to do the Restore, go into Recovery Mode per the instructions here.

  • How to give error message for the screen element text field when wrong i/p

    How to give error message for the screen element text field when wrong i/p
    when wrong input given
    eg. 
    I have a text box with SBOOK-CARRID
    so when user give wrong entry in text box i.e LG
    then I should give some error stating that the the input is invalid or not available ,
    now it showing the error of standard messages,
    i want manual message to be displayed when error comes.
    Thank you,
    Regards,
    Jagrut Bharatkumar Shukla

    Hi all,
    Thank you for your valuable reply,
    but the thing is that its a screen field,
    i.e text box not a selection screen
    i created in screen layout
    with name sbook-carrid
    now i want to get error message display if wrong i/p is given
    thank you.
    Regards,
    Jagrut bharatkumar Shukla,

  • Hi how much is it to replace the screen on the 5c?

    hi how much is it to replace the screen on the 5c?
    Also what does my warranty look like if I bough the phone in October 2013?
    How long would it take to fix?

    Not apple store repair broken screens.
    no warranty for accidental damage, you would have to buy an out of warranty 5C, not sure on the price.

  • How to set default values on the screen painter parameters?

    Hello ABAP Gurus,
    I would just want to ask how to set default values on the screen painter parameters.
    Thank you for your replies.

    Hi,
    To set default values for screen painter parameters initialize the field names with default values in the PBO module....
    say u have the field name as f_field1....
    in the PBO of that screen initialize it....
    f_field1 = '100'  "here 100 is the default value.
    <b>reward points if useful.</b>
    regards,
    Vinod Samuel.

  • Please tell me how to go back to a long text I wrote and then i must have accidentally swiped the screen one way or another.  How do I go back to the screen so I don't have to re-write the whole text?

    Please tell me how to go back to a long text I wrote and then i must have accidentally swiped the screen one way or another.  How do I go back to the screen so I don't have to re-write the whole text?

    Cloud takes over https://forums.adobe.com/thread/1584746 may help

  • How much it costs to fix the screen of an ipad starry

    how much it costs to fix the screen of an ipad starry??????

    Apple's Limited Warranty http://www.apple.com/legal/warranty/ for iPad excludes coverage for damage resulting from accident, disassembly, unauthorized service and unauthorized modifications. 
    Out-of-Warranty Service
         If you own an iPad that is ineligible for warranty service but is eligible for Out-of-Warranty (OOW) Service, Apple will replace (Apple doesn't repair) your iPad with an iPad that is new or equivalent to new in both performance and reliability for the Out-of-Warranty Service fee listed below. (The replacement will most likely be a refurbished iPad in a brown box, however, it has a new screen, back and battery.)   
    iPad model
    Out-of-Warranty Service Fee
    iPad mini
    $219
    iPad 3rd, 4th generation
    $299
    iPad 2, iPad
    $249
    A $6.95 shipping fee will be added if service is arranged through Apple and requires shipping. All fees are in US dollars and are subject to local tax.
    Certain damage is ineligible for out-of-warranty service, including catastrophic damage, such as the device separating into multiple pieces, and inoperability caused by unauthorized modifications. However, an iPad that has failed due to contact with liquid may be eligible for out-of-warranty service. See http://support.apple.com/kb/index?page=servicefaq&geo=United_States&product=ipad
    Make a Genius Bar Reservation
    http://www.apple.com/retail/geniusbar/
    You may can get the iPad repaired at 3rd party repair sources for less $, however, any remaining Apple warranty will be voided.
    iPad Repair & Screen Replacement Services
    http://www.ifixyouri.com/16-ipad-repairs
    RepairZoom iPad Repair
    http://www.repairzoom.com/ipad-repair.html
    Mission Repair
    http://www.missionrepair.com/Apple_iPad_Repair_Services_s/431.htm
    iGadgetResQ
    http://www.igadgetresq.com/ipad-repair/
     Cheers, Tom

  • I bought iMac 27 quad core i7 last June. Last month i have noticed lots of dark patches on the screen and now they are growing more. i bought this from US but now i have moved to Kuwait. How much it cost to replace the screen?

    I bought iMac 27 quad core i7 last June. Last month i have noticed lots of dark patches on the screen and now they are growing more. i bought this from US but now i have moved to Kuwait. How much it cost to replace the screen?

    Mac and Mac models are picky about the RAM the Mac needs to see and use.
    As you have found out, the 1067 speed RAM will not work in your year and model iMac.
    You need the 1333 speed RAM.
    If, you can return the RAM for a refund, do it!
    If not, try online Mac RAM source and seller Crucial memory. They have a table that matches your Mac to the correct and reliable RAM. You may need to contact them to see whether or not they ship to South Africa, though.
    If Crucial dpesn't work out, here's the specs for your year and model iMac that you need to seek out and purchase.
    Maximum Memory
    32 GB (Actual) 16 GB (Apple)
    Memory Slots
    4 - 204-pin PC3-10600 (1333 MHz) DDR3 SO-DIMM
    Good Luck!

  • INSTALLING LION for the first time how long does it take. The screen is white, nothing is happening?

    Installing Lion on a new imac. How long does it take. The screen it white for awhile?

    After downloading it, which can be like watching grass grow, it should take about 20-30 minutes. However, if it's a new computer, why would you installing it?

  • URGENT: How to fix an application with the screen resolution?

    HI everyone,
    I am desprate and need help.. I have developed an application with Java swing and awt (JFrames, JPanels and...). This application displays perfectly with 1280 x 1024 screen resolution but in a situation where the screen does not support this resolution, a part of my application will not appear. I can not even scroll down to see the reste of the components. Does any one has any idea that how I can resolve this problem! I mean how either I can make my JFrame or panel to scroll down or to change the size of the components according to the resolution!
    Thank you very much and wait for a reply :)

    One of the possible reason of the problem is you must have hardcoded the size of panels and other container that is just right for the screen resolution 1280 x 1024.
    The solution is set the size of the containers that depends on the resolution of the screen.
    You have not explained much detail about the scrolling problem. But I suppose that you have a scrollpane in you GUI and you want to scroll the component inside it even at another resolution.
    try using this
    if p is the panel that is added in the scrollpane then set its prefered size.
    p.setPreferredSize(resolution dependant size).

  • How to make a movie of the Screen

    In OS 9 I was able to make a QuickTime of the screen while I was drawing in Photoshop. But that was a long time ago. How does it work in OS X Tiger. My old mac had a microphone. My new G5 imac does not.

    You can still capture a screen in OS X. It saves your captures as .png image files to your Desktop.
    Command-Shift-3 will capture all your see. Command-Shift-4 will turn your mouse into cross-hairs that you drag across any area. And a click on the spacebar (after the above keyboard commands) will turn your cursor into a camera icon that can capture individual windows. Still free.
    Snapz Pro allows you to capture (as QuickTime video) anything in its window. It continues to capture until you close it.
    One of my "movies" made with it:
    http://homepage.mac.com/kkirkster/mycareerfuture/
    Only 1.3MB's and it "plays" full screen.

  • How much for apple to repair the screen ?

    Hi ive cracked my ipod screen - how much is it for apple to repair it ?

    Apple will exchange your iPod for a refurbished one for this price. They do not fix yours. Price depends upon model and capacity
    Apple - iPod Repair price
    You can do it at an Apple store by making an appointment:
    Apple Retail Store - Genius Bar
    or send it in to Apple. See:     
    Service Answer Center - iPod
    A third-party place like the following maybe less. Google for more.
    iPhone Repair, Service & Parts: iPod Touch, iPad, MacBook Pro Screens         
    Replace the screen yourself if you are up to it
    iPod Touch Repair – iFixit                  

Maybe you are looking for

  • DELETE TABLE STATEMENT WITHIN A LOOP IN A PROCEDURE

    i am using delete table tablename statement inside a cursor for loop which is inside a procedure it is telling error in that delete statement can't i put it inside the loop

  • Running iTunes in two windows at the same time

    How can I simultaneously view two windows with different playlist on each one? I remember, that was possible in the previous version of iTunes.

  • Error in ODS Update Rules.

    Hi, We have an abap routine in an ODS Update rules to get FISC YEAR (type NUMC 4) with a field FISCPER(numc 7) from a table. This routine worked fine. But now we moved the abap routine to cmod program in r/3, and when I am doing a direct mapping of f

  • Lightroom 3 not accessing printer profiles

    I'm not able to access newly installed Epson R3000 printer profiles when I go to print in Lightroom 3.  The profiles do show up when I to print in PS3. I'm operating under 10.5.8 on my imac.

  • New to LiveCycle - Submit Email problem

    When I try to distribute a form LiveCycle wants to attach the form to my email. I'm using Yahoo mail. The LiveCycle attachment specifies the folder for the attachment but I've tracked it down to a hidden system folder. Is there a way to specify the f