Java JDialog Center resizeAndCenter(JDialog dialog, double factor)

Here you can find the source of resizeAndCenter(JDialog dialog, double factor)

Description

Resizes a JDialog by a given factor based on the client's screen size.

License

LGPL

Parameter

Parameter Description
dialog a parameter
factor a parameter

Declaration

public static void resizeAndCenter(JDialog dialog, double factor) 

Method Source Code

//package com.java2s;
//License from project: LGPL 

import java.awt.Dimension;

import java.awt.Toolkit;

import javax.swing.JDialog;

public class Main {
    /**/*from  www  .  ja va2  s .com*/
     * Resizes a {@link JDialog} by a given factor based on the client's screen
     * size. The screen is centered afterwards.
     * 
     * @param dialog
     * @param factor
     */
    public static void resizeAndCenter(JDialog dialog, double factor) {
        Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
        dialog.setSize((int) Math.round(screenSize.width * factor), (int) Math.round(screenSize.height * factor));
        centerDialog(dialog);
    }

    /**
     * Centers the dialog on the screen.
     * 
     * @param dialog
     */
    public static void centerDialog(JDialog dialog) {
        dialog.setLocationRelativeTo(null);
    }
}

Related

  1. centrarVentana(JDialog pDialog)
  2. getCentralDialogLocation(Component parent, JDialog dialog)
  3. getCentredDialogBounds(JDialog dialog, Component parent, int defaultWidth, int defaultHeight)
  4. packAndCenterJDialog(JDialog form)
  5. packInCenter(JDialog dialog)
  6. setDialogCenter(JDialog frame)
  7. setDialogWindowToCenter(JDialog dialog)
  8. showCenteredDialog(final JDialog dialog)