Java JDialog isInsideScreen(JDialog component)

Here you can find the source of isInsideScreen(JDialog component)

Description

Checks if component is inside the screen bounds

License

Open Source License

Parameter

Parameter Description
component - JDialog component which position is checked

Return

true if component inside the screen bounds, false otherwise

Declaration

public static boolean isInsideScreen(JDialog component) 

Method Source Code


//package com.java2s;
//License from project: Open Source License 

import java.awt.GraphicsDevice;
import java.awt.GraphicsEnvironment;

import java.awt.Rectangle;
import javax.swing.JDialog;

public class Main {
    /**/*  www.  j  a  v a2 s  .  c o m*/
     * Checks if component is inside the screen bounds
     * @param component - JDialog component which position is checked
     * @return true if component inside the screen bounds, false otherwise
     */
    public static boolean isInsideScreen(JDialog component) {
        boolean inside;
        Rectangle virtualBounds = getVirtualBounds();
        inside = virtualBounds.contains(component.getBounds());
        return inside;
    }

    /**
     * Returns the screen bounds.
     * @return bounds of the screen
     */
    public static Rectangle getVirtualBounds() {
        Rectangle bounds = new Rectangle(0, 0, 0, 0);
        GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
        GraphicsDevice lstGDs[] = ge.getScreenDevices();
        for (GraphicsDevice gd : lstGDs) {
            bounds.add(gd.getDefaultConfiguration().getBounds());
        }
        return bounds;
    }
}

Related

  1. fit(JDialog d)
  2. getJDialog(JComponent c)
  3. getRootJDialog(Component component)
  4. getRootJDialog(java.awt.Component c)
  5. initialiseFrame(JDialog frame, JScrollPane viewport)
  6. jointButton(JDialog frame, final JButton button)
  7. makeJDialogCancellable(final Window w, final Action cancelAction, final boolean disposeOnCancel)
  8. messageDialog(String string, JDialog parentDialog)
  9. openDialog(final JDialog dialog)