Java Code Examples for javax.swing.JFrame.getLocationOnScreen()

The following are Jave code examples for showing how to use getLocationOnScreen() of the javax.swing.JFrame class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
+ Save this method
Example 1
Project: pm-home-station   File: Station.java   View Source Code Vote up 5 votes
private void saveScreenAndDimensions(JFrame frame) {
    if (!frame.isVisible()) {
        return;
    }

    // check multiple displays
    GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
    GraphicsDevice[] screens = ge.getScreenDevices();
    Point pos = frame.getLocationOnScreen();
    Dimension size = frame.getSize();
    if (screens.length == 1) {
        Config.instance().to().setProperty(Config.Entry.POS_X.key(), pos.x);
        Config.instance().to().setProperty(Config.Entry.POS_Y.key(), pos.y);
        Config.instance().to().setProperty(Config.Entry.POS_WIDTH.key(), size.width);
        Config.instance().to().setProperty(Config.Entry.POS_HEIGHT.key(), size.height);
        logger.info("Saved window dimensions to config file (single screen found)");
    } else {
        Rectangle screenBounds = frame.getGraphicsConfiguration().getBounds();
        pos.x -= screenBounds.x;
        pos.y -= screenBounds.y;
        GraphicsDevice device = frame.getGraphicsConfiguration().getDevice();
        Config.instance().to().setProperty(Config.Entry.SCREEN_POS_X.key(), pos.x);
        Config.instance().to().setProperty(Config.Entry.SCREEN_POS_Y.key(), pos.y);
        Config.instance().to().setProperty(Config.Entry.SCREEN_POS_WIDTH.key(), size.width);
        Config.instance().to().setProperty(Config.Entry.SCREEN_POS_HEIGHT.key(), size.height);
        
        Config.instance().to().setProperty(Config.Entry.SCREEN.key(), device.getIDstring());
        logger.info("Saved window dimensions to config file (multi screen found)");
    }
    
}