UIUtilities.java Source code

Java tutorial

Introduction

Here is the source code for UIUtilities.java

Source

import javax.swing.*;
import java.awt.*;

/**
 * @author Adrian BER (beradrian@yahoo.com)
 */
public class UIUtilities {

    public static void setFrameLocationRelativeTo(JFrame f, Component c) {
        if (c == null) {
            // Setting the position of the dialog on the center of the screen
            // in 1.4 should be replaced by
            //             f.setLocationRelativeTo(null);
            Dimension d = Toolkit.getDefaultToolkit().getScreenSize();
            f.setLocation((int) d.getWidth() / 2 - (int) f.getPreferredSize().getWidth() / 2,
                    (int) d.getHeight() / 2 - (int) f.getPreferredSize().getHeight() / 2);
        }
    }
}