Here you can find the source of getLocationFromMouse(Dimension panelPrefSize_)
public static Rectangle getLocationFromMouse(Dimension panelPrefSize_)
//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*/ }