Pregunta

I'm writing an Snipping Tool application. I have connected another moniter to my laptop. Application must recognize which monitor it currently is running on and capture it's screen. Like when I run the application in the external monitor I need to capture the screen of it.

Code I used to do this needed to be provide the monitor number. But I want the application to recognize it.

      GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
      GraphicsDevice[] gs = ge.getScreenDevices();
      gs[0].getDisplayMode();
      Dimension mySize  = new Dimension(width, height);
      width = (int) mySize.getWidth();
      height = (int) mySize.getHeight();
¿Fue útil?

Solución

You can do this:

JFrame frame = new JFrame();
// ...
GraphicsDevice device = frame.getGraphicsConfiguration().getDevice();
Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top