Getting the list of displays attached

Hey mates, let's say I have two monitors attached, I want to put my sketch in fullScreen() on one of them. Is it possible to get a list of the displays attached to the system in processing?


  • edited January 2016 Answer ✓

    What do you want to be on that list? Cause if you put fullScreen(2), it would always run on second, additional monitor.

    On the internet I found some code:

    import java.awt.GraphicsEnvironment;
    import java.awt.GraphicsDevice;
    import java.awt.HeadlessException;
    GraphicsEnvironment env = GraphicsEnvironment.getLocalGraphicsEnvironment();
    GraphicsDevice[] devices = env.getScreenDevices();
    int numberofScreens = devices.length;

    Here's reference on GraphicsDevice. So you can see what information you can get out of it.

  • Thanks for the reply!! I know you can use fullScreen(2) but if you're making a GUI its easier to list screen name (if possible) instead of screen 1,2,3 etc.

  • edited January 2016

    You need to use getIDstring() method then. Like:

    for (GraphicsDevice d: devices){
    String s = d.getIDstring();
  • Nice. Is it possible to access the same descriptions windows or any OS uses to identify the screen?

  • I have no Idea, the best way to know is to try the code on different OS.

  • What I mean is .getIDstring() shows \display0. Windows screens tab shows "Mobile PC Display". Is there a way of getting that description in java?

  • That's a bit too deep, but if you want, you can research:

  • Hmm interesting. Yea I think I'll be ok with just the display number. Thanks again for your help!

  • I noticed fullScreen() doesn't work in processing 3.0a5. Is there another way of switching screens mid-sketch?

Sign In or Register to comment.