Example usage for java.awt Window getSize

List of usage examples for java.awt Window getSize

Introduction

In this page you can find the example usage for java.awt Window 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:Unicode.java

public void centre(Window c) {
    Dimension us = c.getSize(), them = Toolkit.getDefaultToolkit().getScreenSize();
    int newX = (them.width - us.width) / 2;
    int newY = (them.height - us.height) / 2;
    c.setLocation(newX, newY);//from  w  ww .  j  a va  2s  .c om
}

From source file:de.erdesignerng.util.ApplicationPreferences.java

public void updateWindowSize(String aAlias, Window aWindow) {
    Dimension theSize = aWindow.getSize().getSize();
    windowDefinitions.put(WINDOWWIDTHPREFIX + aAlias, "" + theSize.width);
    windowDefinitions.put(WINDOWHEIGHTPREFIX + aAlias, "" + theSize.height);
}

From source file:com.diversityarrays.kdxplore.trials.TrialSelectionDialog.java

public TrialSelectionDialog(Window owner, String title, DALClient c, List<Trial> kdxTrials,
        Transformer<BackgroundRunner, TrialSearchOptionsPanel> searchOptionsPanelFactory) {
    super(owner, title, USE_TRIALS);

    setGlassPane(backgroundRunner.getBlockingPane());

    searchOptionsPanel = searchOptionsPanelFactory.transform(backgroundRunner);
    helpInstructions = new JLabel(searchOptionsPanel.getHtmlHelp(GET_TRIALS));

    kdxTrialByIdDownloaded = kdxTrials.stream().filter(t -> t.getIdDownloaded() != null)
            .collect(Collectors.toMap(Trial::getIdDownloaded, java.util.function.Function.identity()));

    trialRecordTable.setName(this.getClass().getName() + ".trialRecordTable"); //$NON-NLS-1$

    TableColumnModel tcm = trialRecordTable.getColumnModel();
    TableCellRenderer cellRenderer = new OptionalCheckboxRenderer("Already downloaded");
    tcm.getColumn(trialRecordTableModel.getChosenColumnIndex()).setCellRenderer(cellRenderer);

    for (int col = tcm.getColumnCount(); --col >= 0;) {
        if ("TrialName".equals(trialRecordTable.getColumnName(col))) {
            TableColumn tc = tcm.getColumn(col);
            tc.setCellRenderer(new TrialNameCellRenderer());
            break;
        }/*from ww w .j  a va2s .  c  om*/
    }

    findTrialRecords.setEnabled(false);

    searchOptionsPanel.addSearchOptionsChangeListener(searchOptionsListener);
    wantTrialUnits.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            filteringClauseUsed = null;
            handleSearchOptionsChoiceChanged();
        }
    });

    setDALClient(c);

    initialiseGui();

    if (owner != null) {
        Dimension ownerSize = owner.getSize();
        Dimension mySize = getSize();
        int w = (ownerSize.width * 3) / 4;
        int h = (ownerSize.height * 3) / 4;
        if (w > mySize.width || h > mySize.height) {
            if (w > mySize.width) {
                mySize.width = w;
            }
            if (h > mySize.height) {
                mySize.height = h;
            }
            setSize(mySize);
        }
    }

    // TODO consider using setSize to increase to parent's width
    getOkAction().setEnabled(false);
    trialRecordTableModel.addTableModelListener(new TableModelListener() {
        @Override
        public void tableChanged(TableModelEvent e) {
            getOkAction().setEnabled(trialRecordTableModel.getAnyChosen());
        }
    });
}

From source file:edu.ku.brc.ui.UIHelper.java

/**
 * Center and make the window visible/*  w  w w.  j a v a2 s .  c o m*/
 * @param window the window to center
 * @param width sets the dialog to this width (can be null)
 * @param height sets the dialog to this height (can be null)
 */
public static void centerWindow(final java.awt.Window window, final Integer width, final Integer height) {
    JFrame topFrame = (JFrame) UIRegistry.getTopWindow();
    Insets screenInsets = null;
    Rectangle screenRect = null;

    if (width != null || height != null) {
        Dimension s = window.getSize();
        if (width != null)
            s.width = width;
        if (height != null)
            s.height = height;
        window.setSize(s);
    }

    // if there is a registered TOPFRAME, and it's not the same as the window being passed in...
    if (topFrame != null && topFrame != window) {
        screenRect = topFrame.getBounds();
        screenInsets = topFrame.getInsets();
    } else {
        screenRect = window.getGraphicsConfiguration().getBounds();
        screenInsets = Toolkit.getDefaultToolkit().getScreenInsets(window.getGraphicsConfiguration());
    }

    // Make sure we don't place the demo off the screen.
    int centerWidth = screenRect.width < window.getSize().width ? screenRect.x
            : screenRect.x + screenRect.width / 2 - window.getSize().width / 2;
    int centerHeight = screenRect.height < window.getSize().height ? screenRect.y
            : screenRect.y + screenRect.height / 2 - window.getSize().height / 2;

    centerHeight = centerHeight < screenInsets.top ? screenInsets.top : centerHeight;

    window.setLocation(centerWidth, centerHeight);
}

From source file:op.tools.SYSTools.java

public static void center(java.awt.Window w) {
    Dimension us = w.getSize();
    Dimension them = java.awt.Toolkit.getDefaultToolkit().getScreenSize();
    int newX = (them.width - us.width) / 2;
    int newY = (them.height - us.height) / 2;
    w.setLocation(newX, newY);//w  w  w  .j  av  a  2s.  co m
}

From source file:org.apache.cayenne.modeler.util.CayenneController.java

/**
 * Centers view on parent window.//from   w  ww  . j  a v  a 2 s  .  co m
 */
protected void centerView() {
    Window parentWindow = parent.getWindow();

    Dimension parentSize = parentWindow.getSize();
    Dimension windowSize = getView().getSize();
    Point parentLocation = new Point(0, 0);
    if (parentWindow.isShowing()) {
        parentLocation = parentWindow.getLocationOnScreen();
    }

    int x = parentLocation.x + parentSize.width / 2 - windowSize.width / 2;
    int y = parentLocation.y + parentSize.height / 2 - windowSize.height / 2;

    getView().setLocation(x, y);
}

From source file:org.intermine.common.swing.WindowUtils.java

/**
 * Centre the given window on the screen.
 * /*  w ww .  j  a  v  a2  s  . c  o  m*/
 * @param win The Window to position.
 */
public static void centreOnScreen(Window win) {
    Dimension screenRes = Toolkit.getDefaultToolkit().getScreenSize();
    Dimension windowSize = win.getSize();

    int x = Math.max(0, (screenRes.width - windowSize.width) / 2);
    int y = Math.max(0, (screenRes.height - windowSize.height) / 2);

    win.setLocation(x, y);
}

From source file:org.intermine.common.swing.WindowUtils.java

/**
 * Centre the window <code>win</code> over the window <code>parent</code>.
 * /*from   www .  ja  va  2  s. c om*/
 * @param win The Window to position.
 * @param parent The reference Window.
 */
public static void centreOverWindow(Window win, Window parent) {
    Rectangle parentBounds = parent.getBounds();
    Dimension windowSize = win.getSize();

    int x = (parentBounds.width - windowSize.width) / 2;
    int y = (parentBounds.height - windowSize.height) / 2;

    x = Math.max(0, x + parentBounds.x);
    y = Math.max(0, y + parentBounds.y);

    win.setLocation(x, y);
}

From source file:org.pgptool.gui.ui.tools.UiUtils.java

public static void centerWindow(Window frm) {
    Dimension scrDim = Toolkit.getDefaultToolkit().getScreenSize();
    int x = (scrDim.width - frm.getSize().width) / 2;
    int y = (scrDim.height - frm.getSize().height) / 2;
    frm.setLocation(x, y);//from   ww  w . j a  va 2  s .  c  om
}

From source file:org.revager.tools.GUITools.java

/**
 * Sets the location of the given window to cursor position.
 * //  ww  w .  j a  v  a2 s  . c  om
 * @param win
 *            the window for which the location is to be set
 */
public static void setLocationToCursorPos(Window win) {
    Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();

    double cursorPosX = MouseInfo.getPointerInfo().getLocation().getX();
    double cursorPosY = MouseInfo.getPointerInfo().getLocation().getY();

    double screenWidth = screenSize.getWidth();
    double screenHeight = screenSize.getHeight() - 40;

    double winWidth = win.getSize().getWidth();
    double winHeight = win.getSize().getHeight();

    int winPosX = (int) cursorPosX;
    int winPosY = (int) cursorPosY;
    // If the window would break the screen size
    if (cursorPosX + winWidth > screenWidth) {
        winPosX = (int) (screenWidth - winWidth);
    }
    if (cursorPosY + winHeight > screenHeight) {
        winPosY = (int) (screenHeight - winHeight);
    }
    win.setLocation(new Point(winPosX, winPosY));
}