当前位置: 首页>>代码示例>>Java>>正文


Java Window.getLocationOnScreen方法代码示例

本文整理汇总了Java中java.awt.Window.getLocationOnScreen方法的典型用法代码示例。如果您正苦于以下问题:Java Window.getLocationOnScreen方法的具体用法?Java Window.getLocationOnScreen怎么用?Java Window.getLocationOnScreen使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在java.awt.Window的用法示例。


在下文中一共展示了Window.getLocationOnScreen方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: main

import java.awt.Window; //导入方法依赖的package包/类
public static void main(final String[] args) throws AWTException {
    final Window window = new BackgroundIsNotUpdated(null);
    window.setSize(300, 300);
    window.setLocationRelativeTo(null);
    window.setVisible(true);
    sleep();
    window.setBackground(Color.GREEN);
    sleep();
    final Robot robot = new Robot();
    robot.setAutoDelay(200);
    Point point = window.getLocationOnScreen();
    Color color = robot.getPixelColor(point.x + window.getWidth() / 2,
                                      point.y + window.getHeight() / 2);
    window.dispose();
    if (!color.equals(Color.GREEN)) {
        throw new RuntimeException(
                "Expected: " + Color.GREEN + " , Actual: " + color);
    }
}
 
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:20,代码来源:BackgroundIsNotUpdated.java

示例2: main

import java.awt.Window; //导入方法依赖的package包/类
public static void main(final String[] args) throws AWTException {
    final Window window = new BackgroundIsNotUpdated(null);
    window.setSize(300, 300);
    window.setLocationRelativeTo(null);
    window.setVisible(true);
    window.requestFocus();
    final ExtendedRobot robot = new ExtendedRobot();
    robot.setAutoDelay(200);
    robot.waitForIdle(1000);
    window.setBackground(Color.GREEN);
    robot.waitForIdle(1000);
    Point point = window.getLocationOnScreen();
    Color color = robot.getPixelColor(point.x + window.getWidth() / 2,
                                      point.y + window.getHeight() / 2);
    window.dispose();
    if (!color.equals(Color.GREEN)) {
        throw new RuntimeException(
                "Expected: " + Color.GREEN + " , Actual: " + color);
    }
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:21,代码来源:BackgroundIsNotUpdated.java

示例3: calculatePosition

import java.awt.Window; //导入方法依赖的package包/类
private Point calculatePosition(Component source) {
	int xSource = source.getLocationOnScreen().x;
	int ySource = source.getLocationOnScreen().y;

	// get size of popup
	Dimension popupSize = ((Component) popupComponent).getSize();
	if (popupSize.width == 0) {
		popupSize = ((Component) popupComponent).getPreferredSize();
	}

	int xPopup = 0;
	int yPopup = 0;

	// get max x and y window positions
	Window focusedWindow = KeyboardFocusManager.getCurrentKeyboardFocusManager().getActiveWindow();
	int maxX = focusedWindow.getLocationOnScreen().x + focusedWindow.getWidth();
	int maxY = focusedWindow.getLocationOnScreen().y + focusedWindow.getHeight();

	switch (position) {
		case VERTICAL:

			// place popup at sources' x position
			xPopup = xSource;

			// check if popup is outside active window
			if (xPopup + popupSize.width > maxX) {

				// move popup x position to the left
				// to fit inside the active window
				xPopup = maxX - popupSize.width - BORDER_OFFSET;
			}

			// place popup always below source (to avoid overlapping)
			yPopup = ySource + source.getHeight();

			// if the popup now would be moved outside of RM Studio to the left it would look
			// silly, so in that case just show it at its intended position and let it be cut
			// off on the right side as we cannot do anything about it
			if (xPopup < focusedWindow.getLocationOnScreen().x
					|| (xPopup - focusedWindow.getLocationOnScreen().x) + popupSize.width > focusedWindow.getWidth()) {
				xPopup = xSource;
			}

			break;
		case HORIZONTAL:

			// place popup always to the right side of the source (to avoid overlapping)
			xPopup = xSource + source.getWidth();

			yPopup = ySource;

			// check if popup is outside active window
			if (yPopup + popupSize.height > maxY) {

				// move popup upwards to fit into active window
				yPopup = maxY - popupSize.height - BORDER_OFFSET;
			}

			// if the popup now would be moved outside of RM Studio at the top it would look
			// silly, so in that case just show it at its intended position and let it be cut
			// off on the bottom side as we cannot do anything about it
			if (yPopup < focusedWindow.getLocationOnScreen().y
					|| (yPopup - focusedWindow.getLocationOnScreen().y) + popupSize.height > focusedWindow.getHeight()) {
				yPopup = ySource;
			}

			break;
	}

	return new Point(xPopup, yPopup);

}
 
开发者ID:transwarpio,项目名称:rapidminer,代码行数:73,代码来源:PopupAction.java

示例4: saveWindowLocation

import java.awt.Window; //导入方法依赖的package包/类
/**
     * This static method can be used to save the window x,y, position (but not
     * size). This statis method saves the window origin but not the size, based
     * on a classname-based key in the supplied preferences node.
     *
     * @param window the window to save for
     * @param prefs user preferences node
     * @see #restoreWindowLocation
     */
    public static void saveWindowLocation(Window window, Preferences prefs) {
        String name = window.getClass().getName();
        Point p = new Point(0, 0);
        try {
            p = window.getLocationOnScreen();
        } catch (IllegalComponentStateException e) {
            p = window.getLocation();
        }
        prefs.putInt(name + ".XPosition", (int) p.getX());
        prefs.putInt(name + ".YPosition", (int) p.getY());
//        log.info("saved location for window "+name);
    }
 
开发者ID:SensorsINI,项目名称:jaer,代码行数:22,代码来源:WindowSaver.java

示例5: displayStatusDialog

import java.awt.Window; //导入方法依赖的package包/类
/**
 * displays a dialog box describing the status of an event
 */
void displayStatusDialog(Window w, String status) {
    ToolDialog sd = new ToolDialog
            (PolicyTool.getMessage("Status"), tool, this, true);

    // find the location of the PolicyTool gui
    Point location = ((w == null) ?
            getLocationOnScreen() : w.getLocationOnScreen());
    //sd.setBounds(location.x + 50, location.y + 50, 500, 100);
    sd.setLayout(new GridBagLayout());

    JLabel label = new JLabel(status);
    addNewComponent(sd, label, 0,
                    0, 0, 1, 1, 0.0, 0.0, GridBagConstraints.BOTH);

    JButton okButton = new JButton(PolicyTool.getMessage("OK"));
    ActionListener okListener = new StatusOKButtonListener(sd);
    okButton.addActionListener(okListener);
    addNewComponent(sd, okButton, 1,
                    0, 1, 1, 1, 0.0, 0.0, GridBagConstraints.VERTICAL);

    sd.getRootPane().setDefaultButton(okButton);
    sd.getRootPane().registerKeyboardAction(okListener, escKey, JComponent.WHEN_IN_FOCUSED_WINDOW);

    sd.pack();
    sd.setLocationRelativeTo(w);
    sd.setVisible(true);
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:31,代码来源:PolicyTool.java

示例6: displayWarningLog

import java.awt.Window; //导入方法依赖的package包/类
/**
 * display the warning log
 */
void displayWarningLog(Window w) {

    ToolDialog wd = new ToolDialog
            (PolicyTool.getMessage("Warning"), tool, this, true);

    // find the location of the PolicyTool gui
    Point location = ((w == null) ?
            getLocationOnScreen() : w.getLocationOnScreen());
    //wd.setBounds(location.x + 50, location.y + 50, 500, 100);
    wd.setLayout(new GridBagLayout());

    JTextArea ta = new JTextArea();
    ta.setEditable(false);
    for (int i = 0; i < tool.warnings.size(); i++) {
        ta.append(tool.warnings.elementAt(i));
        ta.append(PolicyTool.getMessage("NEWLINE"));
    }
    addNewComponent(wd, ta, 0,
                    0, 0, 1, 1, 0.0, 0.0, GridBagConstraints.BOTH,
                    BOTTOM_PADDING);
    ta.setFocusable(false);

    JButton okButton = new JButton(PolicyTool.getMessage("OK"));
    ActionListener okListener = new CancelButtonListener(wd);
    okButton.addActionListener(okListener);
    addNewComponent(wd, okButton, 1,
                    0, 1, 1, 1, 0.0, 0.0, GridBagConstraints.VERTICAL,
                    LR_PADDING);

    wd.getRootPane().setDefaultButton(okButton);
    wd.getRootPane().registerKeyboardAction(okListener, escKey, JComponent.WHEN_IN_FOCUSED_WINDOW);

    wd.pack();
    wd.setLocationRelativeTo(w);
    wd.setVisible(true);
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:40,代码来源:PolicyTool.java

示例7: displayErrorDialog

import java.awt.Window; //导入方法依赖的package包/类
/**
 * displays a dialog box describing an error which occurred.
 */
void displayErrorDialog(Window w, String error) {
    ToolDialog ed = new ToolDialog
            (PolicyTool.getMessage("Error"), tool, this, true);

    // find where the PolicyTool gui is
    Point location = ((w == null) ?
            getLocationOnScreen() : w.getLocationOnScreen());
    //ed.setBounds(location.x + 50, location.y + 50, 600, 100);
    ed.setLayout(new GridBagLayout());

    JLabel label = new JLabel(error);
    addNewComponent(ed, label, 0,
                    0, 0, 1, 1, 0.0, 0.0, GridBagConstraints.BOTH);

    JButton okButton = new JButton(PolicyTool.getMessage("OK"));
    ActionListener okListener = new ErrorOKButtonListener(ed);
    okButton.addActionListener(okListener);
    addNewComponent(ed, okButton, 1,
                    0, 1, 1, 1, 0.0, 0.0, GridBagConstraints.VERTICAL);

    ed.getRootPane().setDefaultButton(okButton);
    ed.getRootPane().registerKeyboardAction(okListener, escKey, JComponent.WHEN_IN_FOCUSED_WINDOW);

    ed.pack();
    ed.setLocationRelativeTo(w);
    ed.setVisible(true);
}
 
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:31,代码来源:PolicyTool.java

示例8: getCenterPoint

import java.awt.Window; //导入方法依赖的package包/类
private static Point getCenterPoint(Window window) {
    Point centerPoint = window.getLocationOnScreen();
    centerPoint.translate(window.getWidth() / 2, window.getHeight() / 2);
    return centerPoint;
}
 
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:6,代码来源:MissingEventsOnModalDialogTest.java

示例9: getTitlePoint

import java.awt.Window; //导入方法依赖的package包/类
public static Point getTitlePoint(Window decoratedWindow) {
    Point p = decoratedWindow.getLocationOnScreen();
    Dimension d = decoratedWindow.getSize();
    return new Point(p.x + (int)(d.getWidth()/2),
                     p.y + (int)(decoratedWindow.getInsets().top/2));
}
 
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:7,代码来源:Util.java


注:本文中的java.awt.Window.getLocationOnScreen方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。