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

Similar Messages

  • How can I make a intro page for my website, then after the intro has run make the page automatically change to my we site home screen

    how can I make a intro page for my website, then after the intro has run make the page automatically change to my website's home screen

    You can do this using a meta refresh but the problem is you have to add it to the html file for the page very time you publish changes.
    A better way is to create a splash page and upload it to the server outside of the folder produced by iWeb. Example HERE.
    The meta refresh is added to the head section of the html file...
    <meta http-equiv="refresh" content="32;url=http://www.domain.about.com/Page-Name.html">
    The delay time in seconds is marked in blue and the URL to the redirect page is in red.

  • Help - I have an apple id account, where is my iPod and iPad registered, but also the iPod of my daughter. How can I make an account for my daughter and keep all the apps she has on her iPod?

    Help - I have an apple id account, where is my iPod and iPad registered, but also the iPod of my daughter. How can I make an account for my daughter and keep all the apps she has on her iPod and in her own iTunes?

    Sorry, content bought with one Apple ID cannot be merged or transferred to another Apple ID.

  • How can I make albums from events then delete events without deleting the album?

    Hey, just need a little help!
    How can I make albums from events then delete events without deleting the album?
    Many thanks

    You'll be more likely to get help with this if you ask in the iPhoto forum:
    https://discussions.apple.com/community/ilife/iphoto
    You'll need to tell people what version of iPhoto you have so they can give you correct advice.
    Regards.

  • How can I make an external link (to a different folder) from the main menu?

    How can I make an external link (to a different folder) from the main menu?

    If the folder is outside the Muse page, you will have to insert manual HTML to define a more complex URL like e.g. ../_stuff for going one level up and then into a folder called "_stuff" The deeper you are in the hierarchy, the more ../ you will have to add to climb up.
    Mylenium

  • How can I make my apple ID valid for purchases other then the Canadian iTunes Store?

    How can I make my apple ID valid for purchases other then the Canadian iTunes Store? I wanted to download the "Wath abc family" app and it said it had to switch me to the american store because the app isnt available in Canada yet. Once it switched me I put in my apple ID and password and thats when it said that my apple ID is only valid in the canadian store and it switched me back. 
    1)
    2)
    3)

    To make purchases in the Mac App Store/iTunes Store for any particular country, you must be a legal resident of that country and supply a credit card issued by a bank in that country with a verifiable billing address in that country. Do you also make those qualifications in the US?
    But as a side note, as one who has that app, you can only watch both ABC and ABC Family shows if you have an account with a US cable or satelite TV company with which to sign into the app. Otherwise you don't qualify to watch shows with it.

  • How can i make a  flowing toolbar that stays in front of the main frame?

    I want to make a toolbar that has to stay in front of one of my JInternalFrame, this toolbar will have two buttons and they will change the states of some TextPanes in the JInternalFrame (font,styles, etc.). How can i do so?? how can i make it flow on the internalFrame? how can i make it interact with the internal frame's components? and how can i associate both of them ( their 'actionPerform') ??
    thank's

    You can check for problems with the <b>places.sqlite</b> database file in the Firefox profile folder.
    *http://kb.mozillazine.org/Bookmarks_history_and_toolbar_buttons_not_working_-_Firefox
    *https://support.mozilla.org/kb/Bookmarks+not+saved#w_fix-the-bookmarks-file
    *Places Maintenance: https://addons.mozilla.org/firefox/addon/places-maintenance/

  • HT1349 we both have the same Iphone, how can we make sure that we both have different account on the same network?

    my partner and i have the same models of Iphone. how can we make sure that when she logs on to our home network, it recognises her phone and doesn't down load to my phone?

    Did you try to rename one of them? iTunes: How to rename your device
    iTunes remembers the settings for each phone when you sync, even if both phones are called "My iPhone".
    So make sure to set it up like you want to, after that iTunes will do the rest.

  • How can I make my jframe auto streach?

    I have a simple GUI I made in Netbeans and I was wondering if there is a way to make it "autostrech" when I hit the THR button and the lable returns its value
    * To change this template, choose Tools | Templates
    * and open the template in the editor.
    * finaltheclacguiframe.java
    * Created on Oct 19, 2009, 6:29:01 PM
    package finalthrcalcgui;
    * @author newguy45
    public class finalthrcalcguiframe extends javax.swing.JFrame {
        int RHR = 0;
        /** Creates new form finaltheclacguiframe */
        public finalthrcalcguiframe() {
            initComponents();
        /** This method is called from within the constructor to
         * initialize the form.
         * WARNING: Do NOT modify this code. The content of this method is
         * always regenerated by the Form Editor.
        @SuppressWarnings("unchecked")
        // <editor-fold defaultstate="collapsed" desc="Generated Code">                         
        private void initComponents() {
            pulseTextField = new javax.swing.JTextField();
            ageTextField = new javax.swing.JTextField();
            RHRButton = new javax.swing.JButton();
            THRButton = new javax.swing.JButton();
            pulseLable = new javax.swing.JLabel();
            ageLable = new javax.swing.JLabel();
            setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
            setTitle("Target Heart Rate Calculator");
            ageTextField.addActionListener(new java.awt.event.ActionListener() {
                public void actionPerformed(java.awt.event.ActionEvent evt) {
                    ageTextFieldActionPerformed(evt);
            RHRButton.setText("Calculate RHR");
            RHRButton.addActionListener(new java.awt.event.ActionListener() {
                public void actionPerformed(java.awt.event.ActionEvent evt) {
                    RHRButtonActionPerformed(evt);
            THRButton.setText("Calulate THR");
            THRButton.addActionListener(new java.awt.event.ActionListener() {
                public void actionPerformed(java.awt.event.ActionEvent evt) {
                    THRButtonActionPerformed(evt);
            pulseLable.setText("Take your pulse for 10 seconds");
            ageLable.setText("How old are you?");
            javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
            getContentPane().setLayout(layout);
            layout.setHorizontalGroup(
                layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGroup(layout.createSequentialGroup()
                    .addContainerGap()
                    .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                        .addComponent(RHRButton, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                        .addComponent(pulseTextField)
                        .addComponent(THRButton, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                        .addComponent(ageTextField))
                    .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                    .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                        .addComponent(pulseLable)
                        .addComponent(ageLable))
                    .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
            layout.setVerticalGroup(
                layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGroup(layout.createSequentialGroup()
                    .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                        .addComponent(pulseTextField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addComponent(pulseLable, javax.swing.GroupLayout.PREFERRED_SIZE, 17, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                    .addComponent(RHRButton)
                    .addGap(18, 18, 18)
                    .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                        .addComponent(ageTextField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addComponent(ageLable))
                    .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                    .addComponent(THRButton))
            pack();
        }// </editor-fold>                       
        private void RHRButtonActionPerformed(java.awt.event.ActionEvent evt) {                                         
            RHR = (int) (Integer.parseInt(pulseTextField.getText()) * 6);
            pulseLable.setText("RHR: " + RHR);
            public static double THRLowFormula(double THRLowPercent, int maxHeartRateMinusAgeAndRHR, int RHR) {
            double THRLow = maxHeartRateMinusAgeAndRHR * THRLowPercent + RHR;
            return  (int) THRLow;
            public static double THRHighFormula(double THRHighPercent, int maxHeartRateMinusAgeAndRHR, int RHR) {
            double THRHigh = maxHeartRateMinusAgeAndRHR * THRHighPercent + RHR;
            return (int) THRHigh;
        private void ageTextFieldActionPerformed(java.awt.event.ActionEvent evt) {                                            
        private void THRButtonActionPerformed(java.awt.event.ActionEvent evt) {                                         
            int maxHeartRate, age, maxHeartRateMinusAgeAndRHR;
            double THRHigh, THRHighPercent, THRLow, THRLowPercent;
            maxHeartRate = 220;
            age = (int) (Integer.parseInt(ageTextField.getText()));
            maxHeartRateMinusAgeAndRHR = maxHeartRate - age - RHR;
            THRLowPercent = .60;
            THRHighPercent = .70;
            THRLow = THRLowFormula(THRLowPercent, maxHeartRateMinusAgeAndRHR, RHR);
            THRHigh = THRHighFormula(THRHighPercent, maxHeartRateMinusAgeAndRHR, RHR);
            ageLable.setText("Low target heart rate (60%): " + THRLow + " High target heart rate (70%): " + THRHigh);
        * @param args the command line arguments
        public static void main(String args[]) {
            java.awt.EventQueue.invokeLater(new Runnable() {
                public void run() {
                    new finaltheclacguiframe().setVisible(true);
        // Variables declaration - do not modify                    
        private javax.swing.JButton RHRButton;
        private javax.swing.JButton THRButton;
        private javax.swing.JLabel ageLable;
        private javax.swing.JTextField ageTextField;
        private javax.swing.JLabel pulseLable;
        private javax.swing.JTextField pulseTextField;
        // End of variables declaration                  
    }

    newguy45 wrote:
    DrClap, for someone with so many posts I simply cannot believe how much of a douche you are, seriously dude whats your problem were you deprived of oxygen shortly after birth?
    PS: Just because Photobucket is some "unknown" site, try being less of a dick and more agreeable people will enjoy being around youSomeone tries to help you and this is the thanks they get? If someone is going out of their way to help you, the least you could do is go out of your way to make it easy on them.
    Additionally, I find it exceptionally strange that you make assumptions about people's personalities based on the number of posts they have.

  • Please update browser pop up everytime I open firefox........why?........how can I make it stop?....I have the latest firefox version already...annoying!!!!!!!!

    Started tonight 1/23/2014.....I opened firefox and got a new open tab with this message Please update browser.
    I have the latest version of firefox already.....why is this happening?>
    How can It be stopped?
    Please help very annoyed!!!!!

    Whenever you get a message / popup that software / files need to be updated,<br><br>
    <u>'''''DO NOT USE ANY OF THE PROVIDED LINKS'''''</u>.<br><br>
    While this may be a legitimate message, it could also be <u>'''''Malware or a Virus'''''</u>.
    Any time you want or need to check for upgrades,
    go to the web site of the <u>'''''True Owner'''''</u> of the program in question.
    For example, to check out Firefox, go to '''''[https://www.mozilla.org Mozilla.org]'''''
    or '''''[http://www.mozilla.org/en-US/firefox/all/ Firefox In Any Language]'''''.

  • How can I make my email POP account delete emails?

    I use a POP email account. Every time I refresh my email, it brings back all the emails I just deleted.  very frustrating
    I set the Advanced settings to Remove...After one day, UseSSL...OFF, Delete from server...When removed from Inbox, Server Port...110,S/MIME...OFF.
    Why there is no Remove...Immediately is beyond me.
    When I delete emails I want to delete them totally.  Email is one of the main reasons I got an iPad.  Constantly downloading the same emails you deleted extremely limits the usefulness of the iPad2.
    Is there a fix?
    Why doesn't the iPad provide the same functionality for POP accounts as it does for IMAP accounts?

    When I am in mail, I now click back through the navigation boxes on the top left of the screen.  If I am in an email there is a block at the top left of the screen titled "All Inboxes" (43).  The number changes.  click "All Inboxes"  The email list for "All Inboxes" slides in from the left.  Click the navigation arrow titled "Mailboxes" on the top left of the email list.  The "Mailboxes" list slides in to replace "All Inboxes".  The list shows "Inboxes" and "Accounts".  I click the account where I want to delete messages.  I click the "Trash" basket.  The "Trash" bin slides onto the screen.  I click the "Edit" block in the upper right corner.  I select the red "Delete All" in the lower left.  This is a little bit of work.  It currently prevents the emails from constantly coming back to my inboxes.
    My ISP mail provider also appeared to update their system.  I checked their website for directions on using an iPad.  Their suggestions helped.

  • I will sell my touch. how can i make sure that i dont lose any data but the buyer does not access my info.

    i will sell my touch and get the new one. how can i transfer my apps and ID to the new one and erase my info from the old one?
    thanks!

    Yes.  If you do it through the settings on the iPod and have an older iPod, make sure the iPod is charging either via a computer or wall charger.  It can takes hours to erase an older iPod.

  • How can I make open link in new tab cause tabs to the new tab's left to shift left rather than tabs to the new tabs right to shift right?

    When I follow a link in a new tab, the tab opens to the right of the current tab as expected. To make room for the tab on the tab bar, any tabs to the right of the current tab shift right. If there is room for all the tabs on the bar, this behavior is perfect. If however, there isn't sufficient room, some tabs must be hidden to the right or the left of the visible bar. Currently the rightmost visible tab is hidden. This behavior is suboptimal for me because I very often want to switch to tabs on the far right while I very seldom want to switch to tabs on the far left. Is there is a way to cause tabs to the left of the new tab to shift left thereby hiding the leftmost visible tab? Thanks

    I'm not aware of a way to make Firefox hide the first tab instead of the last tab; maybe there is an add-on with that feature.
    There is a hidden setting to open the new tab at the end of the bar instead of next to the page you're reading. Then, of course, you won't have this problem. Instead, you'll have the problem that it's hard to figure out which tab had that link in it. In case you want to try it out, here's how.
    (1) In a new tab, type or paste '''about:config''' in the address bar and press Enter. Click the button promising to be careful.
    (2) In the search box above the list, type or paste '''tabs''' and pause while the list is filtered
    (3) Double-click the '''browser.tabs.insertRelatedAfterCurrent''' preference to switch it from true to false (it should turn bold)
    You're done here. You can keep it open in case you hate the change and watch to switch it right back. In that case, double-click again to switch it back to true.

  • How can I make my page have animations when I click on the link?

    I am doing a class report and I need to come up with something to teach my class in one of our software programs. I am in the middle of Dreamweaver and Access so of course I chose Dreamweaver. I would like to know for my own page as well as to teach my class on how to make my page animated when I click the links.
    In power point you can set animations to your slides. I would like to know how to do almost that same thing but on a website.

    CSS Transitions, Transforms and Animations can do all kinds of fun stuff in modern browsers (everything but IE8 and lower, IE9 can do "some" of it)...
    Transitions
    http://www.w3schools.com/cssref/css3_pr_transition.asp
    Animations and Keyframes
    http://www.w3schools.com/cssref/css3_pr_animation.asp
    http://www.w3schools.com/cssref/css3_pr_animation-keyframes.asp
    Transforms
    http://www.w3schools.com/cssref/css3_pr_transform.asp
    http://www.w3schools.com/css/css3_2dtransforms.asp
    http://www.w3schools.com/css/css3_3dtransforms.asp
    DWCC has a transitions tool, I've never used it, but it's available under Window > CSS Transitions

  • How can I make ringtones show in my Tones tab rather than the Music tab?

    I just bought my first iPhone 4 and uploaded a bunch of music ringtone files to iTunes and changed the default preference to display the Tones tab. However, the ringtones all got added to the Music tab rather than the Tones tab. I have a number of questions:
    I'm used to other phones where any music file can be set as a ringtone for a particular contact. Is this the case for iPhones too?
    If so, how can I set a ringtone for a contact from these music files?
    If not, how can I get the ringtones to appear in the Tones tab? I assume that I would have to do that to sync ringtones to my iPhone ringtone "folder".
    Is there another alternative? I read on the forum something about dragging ringtone files to the iPhone. Not sure I understood that! Does this mean I can drag a music file from the Music tab to the iPhone icon and have that file end up in the iPhone ringtone "folder"? If it ends up in the Music "folder", how do I access it to set it as a contact ringtone?
    Thank you for any light you can shed on this.

    It would be good if this was made a user-defined Option (Tools -> Options -> Tabs) in the next update of Firefox rather than having to install an add-on. I currently keep Firefox open to view my Accuweather.com add-on running or because I know that I will be returning to Firefox in short order. (I do close Firefox if I have visited a sensitive or secure site to ensure better security.) Every time I want to go to a bookmark, I must open a new "(Untitled)" tab before selecting my bookmark using the keyboard (I'm a dedicated keystroker; it's much faster for me). This way, when I close the website, I have an "(Untitled)" tab displaying so that Firefox doesn't close. Why can't I set an Option parameter that will result in me not having to go through this? Alternatively, allow users to set an option to keep Firefox loaded and open in the event only one tab is open and maybe if only one Firefox application window is running (I avoid having more than one Firefox window open as much as possible). I've addressed this last issue in the past but have seen no change when one closes the last tab in a Firefox window. As general practice, I would think that Firefox would run better if options, like I have described above, were part of the Firefox application code and not given to needing an add-on which may cause instability in Firefox as they have in the past, even with author verification and certification.

Maybe you are looking for