You do not need to know if the second monitor is in portrait mode. Just find the borders of the screen in the coordinates of the device and use the center. (If it is in portrait mode, then height> width, but this is not important information).
Your formula for determining the center point of the second device is incorrect. You assume that the coordinates of the second screen are from (w_1,0) to (w_1 + w_2, h_2), but this is not necessarily true. You need to find the GraphicsConfiguration object of the second screen and call GraphicsConfiguration.getBounds () on it. Then you can calculate the center point of this rectangle.
If you want to know which device is on the left or right (either top or bottom), you can compare the x (or y) values โโof their bounding boxes. Note that x or y values โโmay be negative.
source share