1

I am aware that Processing uses variables such as width and height for getting the width and height of a frame. How about if I want to get the maximum width and maximum height of a device in Processing language (specifically in Java mode)?

The maximum height and maximum width of the device I am using such as a laptop or a smartphone or even a tablet.

Kevin Workman
  • 39,413
  • 8
  • 61
  • 94
stego
  • 9
  • 2

2 Answers2

1

The variables displayWidth and displayHeight hold the dimensions of the currently active display. If you use fullScreen(), width and height hold the dimensions too.

ciaron
  • 679
  • 5
  • 15
  • Thanks @ciaron, it worked. I am trying to UpVote your answer but, it says I need to increase my reputation in order to vote. I joined recently. – stego Dec 19 '15 at 00:01
  • Hello @ciaron I was just wondering how can I improve when searching for something? I tried looking in the Processing website API but still haven't been successful. Tried searching for displayWidth in the Processing website but it didn't return anything. How can I improve when searching for something or how did you come across those variables? – stego Dec 19 '15 at 02:13
  • This looks to be undocumented (I couldn't find it in the API either), but I had been digging around in the PApplet source when I found it. (https://github.com/processing/processing/blob/master/core%2Fsrc%2Fprocessing%2Fcore%2FPApplet.java) – ciaron Dec 19 '15 at 06:30
  • Alternatively you can use [Java directly](http://stackoverflow.com/questions/3680221/how-can-i-get-the-monitor-size-in-java/3680236#3680236), because [Processing does the same internally](https://github.com/processing/processing/blob/master/core%2Fsrc%2Fprocessing%2Fcore%2FPApplet.java#L946-L958). – Darius Dec 19 '15 at 14:54
  • Thank you too @Darius M. – stego Dec 20 '15 at 14:27
1

Keep in mind that displayWidth and displayHeight are deprecated as of Processing 3.

Those variables are still available for now though, and here they are in the API. The problem is that there isn't a guarantee that these variables will be there for much longer.

This means that there isn't a "pure Processing" way to get the dimensions of the display. You'll have to implement a different solution for each deployment target you're using.

Community
  • 1
  • 1
Kevin Workman
  • 39,413
  • 8
  • 61
  • 94