java.awt.Window#getLocationOnScreen ( )源码实例Demo

下面列出了java.awt.Window#getLocationOnScreen ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

源代码1 项目: jdk8u-jdk   文件: BackgroundIsNotUpdated.java
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);
    }
}
 
源代码2 项目: jdk8u_jdk   文件: BackgroundIsNotUpdated.java
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);
    }
}
 
源代码3 项目: thunderstorm   文件: HelpButton.java
/**
 * shows the url in the static window, sizes and positions the window
 * accordingly
 */
private void showInTextWindow() throws IOException {
    window.setVisible(false);
    // same height as parent window of the button, positioned next to it on left or right side
    Window ancestor = SwingUtilities.getWindowAncestor(this);
    window.setPreferredSize(new Dimension(WINDOW_WIDTH, Math.max(ancestor.getHeight(), WINDOW_HEIGHT)));
    int screenEnd = ancestor.getGraphicsConfiguration().getBounds().width + ancestor.getGraphicsConfiguration().getBounds().x;
    Point ancestorLocation = ancestor.getLocationOnScreen();
    if(ancestorLocation.x + ancestor.getWidth() + window.getPreferredSize().width < screenEnd) {
        window.setLocation(ancestorLocation.x + ancestor.getWidth(), ancestorLocation.y);
    } else {
        window.setLocation(ancestorLocation.x - window.getPreferredSize().width, ancestorLocation.y);
    }

    //set page shown in browser
    if(url != null && !url.equals(htmlBrowser.getPage())) {
        try {
            htmlBrowser.setPage(url);
        } catch(Exception e) {
            htmlBrowser.setText("Could not load help file");
        }
    }

    window.pack();
    window.setVisible(true);
}
 
源代码4 项目: jdk8u-dev-jdk   文件: BackgroundIsNotUpdated.java
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);
    }
}
 
源代码5 项目: jdk8u-jdk   文件: BackgroundIsNotUpdated.java
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);
    }
}
 
源代码6 项目: jdk8u-jdk   文件: PolicyTool.java
/**
 * 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);
}
 
源代码7 项目: TencentKona-8   文件: PolicyTool.java
/**
 * 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);
}
 
源代码8 项目: TencentKona-8   文件: PolicyTool.java
/**
 * 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);
}
 
源代码9 项目: TencentKona-8   文件: PolicyTool.java
/**
 * 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);
}
 
源代码10 项目: openjdk-jdk8u-backup   文件: PolicyTool.java
/**
 * 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);
}
 
源代码11 项目: openjdk-8-source   文件: PolicyTool.java
/**
 * 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);
}
 
源代码12 项目: jdk8u60   文件: PolicyTool.java
/**
 * 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);
}
 
源代码13 项目: jdk8u60   文件: PolicyTool.java
/**
 * 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);
}
 
源代码14 项目: jdk8u-jdk   文件: PolicyTool.java
/**
 * 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);
}
 
源代码15 项目: openjdk-8   文件: Util.java
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));
}
 
源代码16 项目: openjdk-jdk8u-backup   文件: Util.java
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));
}
 
private static Point getCenterPoint(Window window) {
    Point centerPoint = window.getLocationOnScreen();
    centerPoint.translate(window.getWidth() / 2, window.getHeight() / 2);
    return centerPoint;
}
 
源代码18 项目: openjdk-8-source   文件: Util.java
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));
}
 
源代码19 项目: openjdk-jdk9   文件: Util.java
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));
}
 
源代码20 项目: jdk8u-jdk   文件: Util.java
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));
}