Search code examples
java-melwuit

How to get the number of pixels vertically and horizontally?


I want to show a Dialog with the method signature show(int top, int bottom, int left, int right, boolean includeTitle)

I want to place this Dialog in the center of the screen. So I want to know the total number of pixels of the screen vertically and the total number of pixels of the screen horizontally.

How to achieve that ?


Solution

  • If you're looking for the methods that give you these dimensions in LWUIT then
    you obtain a reference to the Display Display.getInstance()
    then you can call getDisplayHeight() or getDisplayWidth();
    but if you want to use MIDP classes you have to get a reference to the Display
    by calling Display.getDisplay(Midlet instance) and then getting a reference to the
    current Displayable getCurrent() and then you can call getWidth() or getHeight().