Example usage for java.awt Frame getSize

List of usage examples for java.awt Frame getSize

Introduction

In this page you can find the example usage for java.awt Frame getSize.

Prototype

public Dimension getSize() 

Source Link

Document

Returns the size of this component in the form of a Dimension object.

Usage

From source file:Main.java

public static void centerFrame(Frame frame) {
    Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
    Dimension frameSize = frame.getSize();
    if (frameSize.height > screenSize.height) {
        frameSize.height = screenSize.height;
    }//  ww w  .  j  a  v  a2 s .c om
    if (frameSize.width > screenSize.width) {
        frameSize.width = screenSize.width;
    }
    frame.setLocation((screenSize.width - frameSize.width) / 2, (screenSize.height - frameSize.height) / 2);
}

From source file:Main.java

/** Repositions a frame to be centered on the screen */
public static void center(Frame frame) {
    Toolkit tk = Toolkit.getDefaultToolkit();
    Dimension screen = tk.getScreenSize();
    Dimension win = frame.getSize();
    //frame.setSize(screenWidth / 2, screenHeight / 2);
    frame.setLocation((screen.width - win.width) / 2, (screen.height - win.height) / 2);
}

From source file:FontChooser.java

public static Font showDialog(Frame parent, String title, Font font) {
    FontChooser dialog = new FontChooser(parent, true, font);

    Point p1 = parent.getLocation();
    Dimension d1 = parent.getSize();
    Dimension d2 = dialog.getSize();

    int x = p1.x + (d1.width - d2.width) / 2;
    int y = p1.y + (d1.height - d2.height) / 2;

    if (x < 0) {
        x = 0;/*from  w w w .  ja  v  a 2 s .c  om*/
    }
    if (y < 0) {
        y = 0;
    }

    if (title != null) {
        dialog.setTitle(title);
    }
    dialog.setLocation(x, y);
    dialog.setVisible(true);

    Font newfont = null;
    if (dialog.ok) {
        newfont = dialog.getCurrentFont();
    }

    dialog.dispose();
    return newfont;
}

From source file:com.mirth.connect.plugins.rtfviewer.RTFViewer.java

@Override
public void viewAttachments(List<String> attachmentIds) {
    // do viewing code

    Frame frame = new Frame("RTF Viewer");

    frame.setLayout(new BorderLayout());

    try {// ww w.  jav  a 2 s  . c  o m

        Attachment attachment = parent.mirthClient.getAttachment(attachmentIds.get(0));
        byte[] rawRTF = Base64.decodeBase64(attachment.getData());
        JEditorPane jEditorPane = new JEditorPane("text/rtf", new String(rawRTF));

        if (jEditorPane.getDocument().getLength() == 0) {
            // decoded when it should not have been.  i.e.) the attachment data was not encoded.
            jEditorPane.setText(new String(attachment.getData()));
        }

        jEditorPane.setEditable(false);
        JScrollPane scrollPane = new javax.swing.JScrollPane();
        scrollPane.setViewportView(jEditorPane);
        frame.add(scrollPane);
        frame.addWindowListener(new WindowAdapter() {

            public void windowClosing(WindowEvent e) {
                e.getWindow().dispose();
            }
        });

        frame.setSize(600, 800);

        Dimension dlgSize = frame.getSize();
        Dimension frmSize = parent.getSize();
        Point loc = parent.getLocation();

        if ((frmSize.width == 0 && frmSize.height == 0) || (loc.x == 0 && loc.y == 0)) {
            frame.setLocationRelativeTo(null);
        } else {
            frame.setLocation((frmSize.width - dlgSize.width) / 2 + loc.x,
                    (frmSize.height - dlgSize.height) / 2 + loc.y);
        }

        frame.setVisible(true);
    } catch (Exception e) {
        parent.alertException(parent, e.getStackTrace(), e.getMessage());
    }
}

From source file:com.mirth.connect.plugins.textviewer.TextViewer.java

@Override
public void viewAttachments(String channelId, Long messageId, String attachmentId) {
    // do viewing code
    Frame frame = new Frame("Text Viewer");
    frame.setLayout(new BorderLayout());

    try {/*w ww. j  ava  2  s .  co  m*/
        Attachment attachment = parent.mirthClient.getAttachment(channelId, messageId, attachmentId);
        byte[] content = Base64.decodeBase64(attachment.getContent());

        boolean isRTF = attachment.getType().toLowerCase().contains("rtf");
        //TODO set character encoding
        JEditorPane jEditorPane = new JEditorPane(isRTF ? "text/rtf" : "text/plain", new String(content));

        if (jEditorPane.getDocument().getLength() == 0) {
            // decoded when it should not have been.  i.e.) the attachment data was not encoded.
            jEditorPane.setText(new String(attachment.getContent()));
        }

        jEditorPane.setEditable(false);
        JScrollPane scrollPane = new javax.swing.JScrollPane();
        scrollPane.setViewportView(jEditorPane);
        frame.add(scrollPane);
        frame.addWindowListener(new WindowAdapter() {

            public void windowClosing(WindowEvent e) {
                e.getWindow().dispose();
            }
        });

        frame.setSize(600, 800);

        Dimension dlgSize = frame.getSize();
        Dimension frmSize = parent.getSize();
        Point loc = parent.getLocation();

        if ((frmSize.width == 0 && frmSize.height == 0) || (loc.x == 0 && loc.y == 0)) {
            frame.setLocationRelativeTo(null);
        } else {
            frame.setLocation((frmSize.width - dlgSize.width) / 2 + loc.x,
                    (frmSize.height - dlgSize.height) / 2 + loc.y);
        }

        frame.setVisible(true);
    } catch (Exception e) {
        parent.alertThrowable(parent, e);
    }
}

From source file:pl.edu.icm.visnow.lib.utils.ImageUtilities.java

public static void centerFrame(Frame f) {
    Dimension screen = Toolkit.getDefaultToolkit().getScreenSize();
    Dimension d = f.getSize();
    int x = (screen.width - d.width) / 2;
    int y = (screen.height - d.height) / 2;
    f.setLocation(x, y);/*from www . jav a  2s  . c  o  m*/
}

From source file:proci.gui.Importa.java

/** Creates new form Importa */
public Importa(java.awt.Frame parent, boolean modal) {
    super(parent, modal);
    initComponents();// w  w  w .ja  v  a 2 s  .co  m
    Dimension frmSize = parent.getSize();
    Point loc = parent.getLocation();
    this.setSize(IMPO_WIDTH, IMPO_HEIGHT);
    this.setLocation((frmSize.width - IMPO_WIDTH) / 2 + loc.x, (frmSize.height - IMPO_HEIGHT) / 2 + loc.y);
    jepData.setEditable(false);
    jepData.setContentType("text/html");
    String text = "<html><body><font face='verdana,arial' size=+1><p align='center'>Importazione</p></font>"
            + "<p><font color='red'>ATTENZIONE:</font> I dati presenti in archivio verranno eliminati!!</p>"
            + "<p><font color='red'>ATTENZIONE:</font> L'operazione di import/export non  reversibile. Usare "
            + "la funzione di backup per copiare dati tra diverse istanze della procedura!</p>";
    jepData.setText(text);
}

From source file:util.ui.UiUtilities.java

/**
 * Centers a window to its parent frame and shows it.
 * <p>//from   w w  w  . j a  va  2s.  c  o  m
 * If the window has no parent frame it will be centered to the screen.
 *
 * @param win
 *          The window to center and show.
 */
public static void centerAndShow(Window win) {
    Dimension wD = win.getSize();
    Dimension frameD;
    Point framePos;
    Frame frame = JOptionPane.getFrameForComponent(win);

    // Should this window be centered to its parent frame?
    boolean centerToParentFrame = (frame != null) && (frame != win) && frame.isShowing();

    // Center to parent frame or to screen
    if (centerToParentFrame) {
        frameD = frame.getSize();
        framePos = frame.getLocation();
    } else {
        GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
        // dual head, use first screen
        if (ge.getScreenDevices().length > 1) {
            try {
                GraphicsDevice gd = ge.getDefaultScreenDevice();
                GraphicsConfiguration config = gd.getConfigurations()[0];
                frameD = config.getBounds().getSize();
                framePos = config.getBounds().getLocation();
            } catch (RuntimeException e) {
                frameD = Toolkit.getDefaultToolkit().getScreenSize();
                framePos = new Point(0, 0);
            }
        }
        // single screen only
        else {
            frameD = Toolkit.getDefaultToolkit().getScreenSize();
            framePos = new Point(0, 0);
        }
    }

    Point wPos = new Point(framePos.x + (frameD.width - wD.width) / 2,
            framePos.y + (frameD.height - wD.height) / 2);
    wPos.x = Math.max(0, wPos.x); // Make x > 0
    wPos.y = Math.max(0, wPos.y); // Make y > 0
    win.setLocation(wPos);
    win.setVisible(true);
}