Java Code Examples for org.eclipse.swt.widgets.Display#getPrimaryMonitor()

The following examples show how to use org.eclipse.swt.widgets.Display#getPrimaryMonitor() . These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may want to check out the right sidebar which shows the related API usage.
Example 1
Source Project: SWET   File: SWTUtil.java    License: MIT License 6 votes vote down vote up
private static Rectangle getCurrentMonitorBounds(Display dsp) {
	Monitor monitor = dsp.getPrimaryMonitor();

	// Choose current Monitor
	Point cursor = dsp.getCursorLocation();
	Monitor[] monitors = dsp.getMonitors();
	for (Monitor mon : monitors) {
		Rectangle mbounds = mon.getBounds();
		if (mbounds.contains(cursor)) {
			monitor = mon;
			break;
		}
	}

	return monitor.getBounds();
}
 
Example 2
Source Project: SWET   File: ScrolledTextEx.java    License: MIT License 5 votes vote down vote up
private static Point center(Display display, Shell shell) {
	Monitor primary = display.getPrimaryMonitor();
	Rectangle bounds = primary.getBounds();
	Rectangle rect = shell.getBounds();

	int x = bounds.x + (bounds.width - rect.width) / 2;
	int y = bounds.y + (bounds.height - rect.height) / 2;

	Point location = new Point(x, y);
	return location;
}
 
Example 3
Source Project: arx   File: Main.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Returns the monitor on which the application was launched.
 *
 * @param display
 * @return
 */
private static Monitor getMonitor(Display display) {
    Point mouse = display.getCursorLocation();
    for (Monitor monitor : display.getMonitors()) {
        if (monitor.getBounds().contains(mouse)) {
            return monitor;
        }
    }
    return display.getPrimaryMonitor();
}