Java JFrame setWindowRightSide(final JFrame frame)

Here you can find the source of setWindowRightSide(final JFrame frame)

Description

set Window Right Side

License

LGPL

Declaration

public static void setWindowRightSide(final JFrame frame) 

Method Source Code


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

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

public class Main {
    public static void setWindowRightSide(final JFrame frame) {
        frame.setExtendedState(JFrame.NORMAL);
        giveFrameHalfScreen(frame);/*from  w ww  .j  a v a  2  s  .c o  m*/

        GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
        GraphicsDevice defaultScreen = ge.getDefaultScreenDevice();
        Rectangle rect = defaultScreen.getDefaultConfiguration().getBounds();
        int x = (int) rect.getMaxX() - frame.getWidth();
        int y = 0;
        frame.setLocation(x, y);
    }

    private static void giveFrameHalfScreen(final JFrame frame) {
        final Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();

        final Rectangle winSize = GraphicsEnvironment.getLocalGraphicsEnvironment().getMaximumWindowBounds();
        final int taskBarHeight = screenSize.height - winSize.height;

        final int width = (int) (screenSize.width * 0.505);
        final int height = screenSize.height - taskBarHeight;

        frame.setSize(width, height);
    }
}

Related

  1. setJFrameAlwaysOnTop(JFrame frame, boolean newValue)
  2. setMainWindowLocation(JFrame jfrm, String strPropertiesFilePath, String strPropertiesFileName)
  3. setPanel(JPanel parent, JPanel child, JFrame f)
  4. setPersistentExtendedStateMask(JFrame frame, int persistentExtendedStateMask)
  5. setWindowListenerDispose(JFrame frame)
  6. setWinVisible(final JFrame win, final boolean vis)
  7. smartSetBounds(JFrame frame)
  8. staggerOpenedFrames(List frames)
  9. storePrefsFrame(Preferences node, JFrame frame)