wood burning stoves 2.0*
The moose likes Java Micro Edition and the fly likes getHeight() giving wrong height Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCA/OCP Java SE 7 Programmer I & II Study Guide this week in the OCPJP forum!
JavaRanch » Java Forums » Mobile » Java Micro Edition
Bookmark "getHeight() giving wrong height" Watch "getHeight() giving wrong height" New topic
Author

getHeight() giving wrong height

Poonam Gulve
Greenhorn

Joined: Aug 13, 2007
Posts: 16
Hi
On Motorola phones, after setting full screen mode true , when i do screenheight = canvas.getHeight() i get wrong screenheight .. lesser than the actual one.. is there any other way to find the actual screen ht other than hard coding ??


Regards,<br />Poonam Gulve
Rashid Mayes
Ranch Hand

Joined: Jan 11, 2006
Posts: 160
This can be a problem on Nokia devices also. Try getting the screen height by overriding "protected void sizeChanged(int w, int h)"

Try assigning screenHeight a value in this method. The Canvas may need to be visible before this method is called.
[ September 07, 2007: Message edited by: Rashid Mayes ]

Rashid Mayes
http://www.hostj2me.com/ - http://www.worlddeveloper.org/
Poonam Gulve
Greenhorn

Joined: Aug 13, 2007
Posts: 16
hello sir, thanks a lot..

but after overriding that method i'll hv to call it by saying
sizechanged(176,220);
right?? but this is also like hard coding the values .. i mean for other screen size i'll hv to send different values each time..

and After hard coding the values of width=176 and height = 220 and after fillrect(0,0,width,height); fills the entire screen ..

is there any general way ?? and does this problem occurs because of setting setFullScreenMode(true) ???
[ September 10, 2007: Message edited by: Poonam Gulve ]
Rashid Mayes
Ranch Hand

Joined: Jan 11, 2006
Posts: 160
Actually you do not call the method. Please see the javadoc.

"Calling setFullScreenMode(boolean) may result in sizeChanged() being called. The default implementation of this method does nothing. The application can override this method to handle changes in size of available drawing area".

This method will be called, with the correct values, by the container implementation.
Rashid Mayes
Ranch Hand

Joined: Jan 11, 2006
Posts: 160
As an aside, I use



in most of my applications. Take a look at the source code for the Window class in this application http://hostj2me.com/appdetails.html?id=3613
Tim Holloway
Saloon Keeper

Joined: Jun 25, 2001
Posts: 16158
    
  21

I haven't checked the J2ME docs, but I believe that to get the actual physical screen dimensions, you have to call a Toolkit method in regular Java.

One of the tricky things about modern-day displays is that there may be more than one of them. Better yet, on some cell phones, one screen is color and one is monochrome!


Customer surveys are for companies who didn't pay proper attention to begin with.
Rashid Mayes
Ranch Hand

Joined: Jan 11, 2006
Posts: 160
The behavior is documented in the javadoc for the "javax.microedition.lcdui.Canvas" class.

There should be a copy of the Javadoc with your WTK installation. You can also find copies of the Javadoc installed with the SonyEricsson and Motorola developer kit installations.

As for J2SE, indeed there are many toolkit implementations, i.e. sun.awt.X11.XToolkit, sun.awt.motif.MToolkit, and toolkits which wrap other toolkits like sun.awt.HeadlessToolkit.
Syam Sathyan George
Ranch Hand

Joined: Apr 26, 2006
Posts: 64
This is a bug which many UI toolkits have overcomed using the above said above "Rashids Tip" OR by using "Configurations and device specific builds".

Use macros in code which read the configuration and build accordingly. But you will have a lot of screen sizes to be made into configurations etc.

I suggest to use a good UI kit like polish.


Syam.Sathyan.George
(My boss is a Jewish carpenter)
emmanuel beaufort
Greenhorn

Joined: Oct 23, 2007
Posts: 3
getWidth() & getHeight() return correct values when used in paint(Graphics g) method (could be store in global fields).
Amila Jayatillaka
Greenhorn

Joined: Sep 29, 2006
Posts: 28
hey Rashid your answer helped me a lot.Thanks buddy.


SCJP 1.4, SCMAD 1.0, SCWCD 5.0
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: getHeight() giving wrong height