Search
 
SCRIPT & CODE EXAMPLE
 

JAVA

java active displays

Window myWindow = ....
// ...
GraphicsConfiguration config = myWindow.getGraphicsConfiguration();
GraphicsDevice myScreen = config.getDevice();
GraphicsEnvironment env = GraphicsEnvironment.getLocalGraphicsEnvironment();
// AFAIK - there are no guarantees that screen devices are in order... 
// but they have been on every system I've used.
GraphicsDevice[] allScreens = env.getScreenDevices();
int myScreenIndex = -1;
for (int i = 0; i < allScreens.length; i++) {
    if (allScreens[i].equals(myScreen))
    {
        myScreenIndex = i;
        break;
    }
}
System.out.println("window is on screen" + myScreenIndex);
Comment

java active displays

    public static GraphicsDevice getWindowDevice(Window window) {
    Rectangle bounds = window.getBounds();
    return asList(GraphicsEnvironment.getLocalGraphicsEnvironment().getScreenDevices()).stream()

            // pick devices where window located
            .filter(d -> d.getDefaultConfiguration().getBounds().intersects(bounds))

            // sort by biggest intersection square
            .sorted((f, s) -> Long.compare(//
                    square(f.getDefaultConfiguration().getBounds().intersection(bounds)),
                    square(s.getDefaultConfiguration().getBounds().intersection(bounds))))

            // use one with the biggest part of the window
            .reduce((f, s) -> s) //

            // fallback to default device
            .orElse(window.getGraphicsConfiguration().getDevice());
}

public static long square(Rectangle rec) {
    return Math.abs(rec.width * rec.height);
}
Comment

PREVIOUS NEXT
Code Example
Java :: what is serialization in rest assured 
Java :: Copying Arrays Using Assignment Operator Java 
Java :: java code to compare csv file against a table 
Java :: crazy error 
Java :: editable column 
Java :: java makefile clean bin 
Java :: java cors issue 
Java :: least significant bit java 
Java :: java jpanel popup message 
Java :: Use following code to open activity while your application is not running. 
Java :: how to romve a element from arraylist in java 
Java :: Create all possible substrings of a string java 
Java :: Java 8 merge multiple collections using flatmap 
Java :: java mockito subclass mocken method 
Java :: Java assertion with expression example 
Java :: place.getlatlng() returning null 
Java :: records java final 
Java :: xml definition file for spring 
Java :: array slicing 
Java :: why is write replacing my text java 
Java :: Log exception details to string 
Java :: Java labeled break Statement 
Java :: data base spring 
Java :: generate paranthesis 
Java :: min_value java 
Java :: how to array list with a delimiter into text file java 
Java :: try catch still prints java 
Java :: spring data rest relationships 
Java :: MinimumAndMaximum 
Java :: why is button hover not working in java netbeans 
ADD CONTENT
Topic
Content
Source link
Name
1+3 =