Java Code Examples for java.awt.Window#getLocationOnScreen()

The following examples show how to use java.awt.Window#getLocationOnScreen() . 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 check out the related API usage on the sidebar.
Example 1
Source File: BackgroundIsNotUpdated.java    From jdk8u_jdk with GNU General Public License v2.0 6 votes vote down vote up
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);
    }
}
 
Example 2
Source File: BackgroundIsNotUpdated.java    From jdk8u-jdk with GNU General Public License v2.0 6 votes vote down vote up
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);
    }
}
 
Example 3
Source File: BackgroundIsNotUpdated.java    From jdk8u-jdk with GNU General Public License v2.0 6 votes vote down vote up
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);
    }
}
 
Example 4
Source File: HelpButton.java    From thunderstorm with GNU General Public License v3.0 6 votes vote down vote up
/**
 * 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);
}
 
Example 5
Source File: BackgroundIsNotUpdated.java    From jdk8u-dev-jdk with GNU General Public License v2.0 6 votes vote down vote up
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);
    }
}
 
Example 6
Source File: PolicyTool.java    From jdk8u-jdk with GNU General Public License v2.0 5 votes vote down vote up
/**
 * 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);
}
 
Example 7
Source File: PolicyTool.java    From jdk8u60 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * 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);
}
 
Example 8
Source File: PolicyTool.java    From jdk8u60 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * 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);
}
 
Example 9
Source File: PolicyTool.java    From openjdk-8-source with GNU General Public License v2.0 5 votes vote down vote up
/**
 * 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);
}
 
Example 10
Source File: PolicyTool.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 5 votes vote down vote up
/**
 * 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);
}
 
Example 11
Source File: PolicyTool.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * 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);
}
 
Example 12
Source File: PolicyTool.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * 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);
}
 
Example 13
Source File: PolicyTool.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * 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);
}
 
Example 14
Source File: PolicyTool.java    From jdk8u-jdk with GNU General Public License v2.0 5 votes vote down vote up
/**
 * 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);
}
 
Example 15
Source File: MissingEventsOnModalDialogTest.java    From TencentKona-8 with GNU General Public License v2.0 4 votes vote down vote up
private static Point getCenterPoint(Window window) {
    Point centerPoint = window.getLocationOnScreen();
    centerPoint.translate(window.getWidth() / 2, window.getHeight() / 2);
    return centerPoint;
}
 
Example 16
Source File: Util.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 4 votes vote down vote up
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));
}
 
Example 17
Source File: Util.java    From openjdk-8-source with GNU General Public License v2.0 4 votes vote down vote up
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));
}
 
Example 18
Source File: Util.java    From openjdk-jdk9 with GNU General Public License v2.0 4 votes vote down vote up
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));
}
 
Example 19
Source File: Util.java    From openjdk-8 with GNU General Public License v2.0 4 votes vote down vote up
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));
}
 
Example 20
Source File: Util.java    From jdk8u-jdk with GNU General Public License v2.0 4 votes vote down vote up
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));
}