Java JComponent Container centerOnComponet(Window target, JComponent parent)

Here you can find the source of centerOnComponet(Window target, JComponent parent)

Description

center On Componet

License

Apache License

Declaration

public static void centerOnComponet(Window target, JComponent parent) 

Method Source Code

//package com.java2s;
/*******************************************************************************
 * Copyright 2011 Krzysztof Otrebski//from w ww .  j  av a  2  s  . com
 * 
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 * 
 *   http://www.apache.org/licenses/LICENSE-2.0
 * 
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 ******************************************************************************/

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

public class Main {
    public static void centerOnComponet(Window target, JComponent parent) {
        Dimension targetSize = target.getSize();
        Point location = parent.getLocationOnScreen();
        Dimension sourceSize = parent.getSize();

        Point sourceCenter = new Point(location.x + sourceSize.width / 2,
                location.y + sourceSize.height / 2);
        Point frameLocation = new Point(sourceCenter.x - targetSize.width
                / 2, sourceCenter.y - targetSize.height / 2);
        target.setLocation(frameLocation);
    }
}

Related

  1. allignBottom(JComponent lead, JComponent target)
  2. centerComponent(final JComponent target)
  3. checkComponents(final Component _rootComponent, final String _print, final int _currentColumn, final int _currentRow)
  4. findMainRootPane(Component component)
  5. findRootPane(Component component)
  6. findRootPaneContainer(Component c)