Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

getHeight() giving wrong height

 
Poonam Gulve
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 ??
 
Rashid Mayes
Ranch Hand
Posts: 160
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 ]
 
Poonam Gulve
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 160
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 160
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 18164
53
Android Eclipse IDE Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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!
 
Rashid Mayes
Ranch Hand
Posts: 160
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 64
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
emmanuel beaufort
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
getWidth() & getHeight() return correct values when used in paint(Graphics g) method (could be store in global fields).
 
Amila Jayatillaka
Greenhorn
Posts: 28
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hey Rashid your answer helped me a lot.Thanks buddy.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic