public static int getScreenID ( Component component ) { int screenID ; final AtomicInteger counter = new AtomicInteger ( - 1 ) ; Stream . of ( getScreenDevices ( ) ) . forEach ( graphicsDevice -> { GraphicsConfiguration gc = graphicsDevice . getDefaultConfiguration ( ) ; Rectangle rectangle = gc . getBounds ( ) ; if ( rectangle . contains ( component . getLocation ( ) ) ) { try { Object object = ReflectionExtensions . getFieldValue ( graphicsDevice , "screen" ) ; Integer sid = ( Integer ) object ; counter . set ( sid ) ; } catch ( NoSuchFieldException | SecurityException | IllegalArgumentException | IllegalAccessException e ) { e . printStackTrace ( ) ; } } } ) ; screenID = counter . get ( ) ; return screenID ; }
Gets the screen ID from the given component