Java Screen Size getLocationFromMouse(Dimension panelPrefSize_)

Here you can find the source of getLocationFromMouse(Dimension panelPrefSize_)

Description

get Location From Mouse

License

Open Source License

Declaration

public static Rectangle getLocationFromMouse(Dimension panelPrefSize_) 

Method Source Code

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

import java.awt.Dimension;

import java.awt.GraphicsDevice;

import java.awt.MouseInfo;

import java.awt.Rectangle;

public class Main {
    public static Rectangle getLocationFromMouse(Dimension panelPrefSize_) {
        GraphicsDevice device = MouseInfo.getPointerInfo().getDevice();
        Dimension screensize = new Dimension(device.getDisplayMode().getWidth(),
                device.getDisplayMode().getHeight());
        int x = (screensize.width - panelPrefSize_.width) / 2;
        int y = (screensize.height - panelPrefSize_.height) / 2;

        return new Rectangle(x, y, panelPrefSize_.width, panelPrefSize_.height);
    }/*from   w w  w  .  j  a v a2 s  .c o m*/
}

Related

  1. getDefaultScreenSize()
  2. getDefaultScreenSizeWithoutAdjustment()
  3. getDesktopBounds()
  4. getDesktopBounds()
  5. getLocalScreenBounds()
  6. getMaximumWindowBounds()
  7. getMaximumWindowBounds()
  8. getMaximumWindowWidth()
  9. getMaxSize(Window frame)