Welcome!

Welcome to the official BlackBerry Support Community Forums.

This is your resource to discuss support topics with your peers, and learn from each other.

inside custom component

Java Development

Reply
Developer
jlfrias
Posts: 108
Registered: ‎01-29-2009
My Device: BlackBerry 8700g
My Carrier: Tigo
Accepted Solution

Get width of Screen

Hi team,

 

I have a following code:

 

 

import net.rim.device.api.ui.*; import net.rim.device.api.ui.component.*; import net.rim.device.api.ui.container.*; import net.rim.device.api.i18n.*; import net.rim.device.api.system.*; import net.rim.device.api.collection.util.*; import net.rim.device.api.ui.decor.*; import java.util.*; public final class SeedAboutScreen extends MainScreen implements SeedManagerResource { //members ------------------------------------------------------------------ private static ResourceBundle _resources = ResourceBundle.getBundle(BUNDLE_ID, BUNDLE_NAME); private static SeedHelpScreen _seedHelpScreen; private VerticalFieldManager _manager; public SeedAboutScreen() { super(); _manager = (VerticalFieldManager)getMainManager(); BitmapField image_top = new BitmapField(Bitmap.getBitmapResource(_resources.getString(IMAGE_TOP)), FIELD_HCENTER | FOCUSABLE); Background image_background = BackgroundFactory.createBitmapBackground(Bitmap.getBitmapResource(_resources.getString(IMAGE_BACKGROUND)), 0, 0, Background.REPEAT_INHERIT); BitmapField image_logo = new BitmapField(Bitmap.getBitmapResource(_resources.getString(IMAGE_LOGO)), FIELD_HCENTER | FOCUSABLE); _manager.setBackground(image_background); Font font_title = this.getFont().derive(Font.PLAIN | Font.BOLD); Font font_application = this.getFont().derive(Font.PLAIN, 16); Font font_bold = this.getFont().derive(Font.PLAIN | Font.BOLD, 16); LabelField _titleField = new LabelField(_resources.getString(APPLICATION_TITLE), FOCUSABLE); LabelField _descriptionField = new LabelField(_resources.getString(APPLICATION_DESCRIPTION), FOCUSABLE); LabelField _versionField = new LabelField("Version: " + _resources.getString(APPLICATION_VERSION), 0, -1, Field.FIELD_RIGHT | FOCUSABLE); _titleField.setFont(font_title); _descriptionField.setFont(font_bold); _versionField.setFont(font_bold); try { _manager.add(image_top); _manager.add(_titleField); _manager.add(new LabelField(" ")); _manager.add(_descriptionField); _manager.add(new SeparatorField()); _manager.add(_versionField); _manager.add(new LabelField(" ")); } catch (IllegalArgumentException e) { System.out.println(e.getMessage()); } } public boolean onClose() { _seedHelpScreen = new SeedHelpScreen(); UiApplication.getUiApplication().pushScreen(_seedHelpScreen); return true; } public boolean keyChar(char key, int status, int time) { //intercept the ESC key - back out of this screen on its receipt boolean retval = false; switch (key) { case Characters.ESCAPE: onClose(); retval = true; break; } return retval; } private MenuItem _closeItem = new MenuItem(null, 0 , 200000, 10) { public void run() { onClose(); } public String toString() { return "Close"; } }; protected void makeMenu ( Menu menu, int instance ) { menu.add(_closeItem); } }

 

I need get the width screen for create the following option:

 


Switch (widthScreenDevice())

case 480:

BitmapField image_top = new BitmapField("image 1.png");
case 320:
BitmapField image_top = new BitmapField("image 2.png");

...

 

I don't have idea about this, please help me.

 

Thanks.

 

 

 

 

 

Jorge Luis Frias B

Leader on Development
BlackBerry/iPhone Technologies
Developer
mantaker
Posts: 1,477
Registered: ‎12-30-2008
My Device: Torch 9810

Re: Get width of Screen

Display.getWidth() will get you the screen width!

 

Thanks! 

--
Manimaran Selvan
Co-Founder, Tech Lead,
Equity Markets Research Group
Developer
jlfrias
Posts: 108
Registered: ‎01-29-2009
My Device: BlackBerry 8700g
My Carrier: Tigo

Re: Get width of Screen

Thanks, but How can insert this function "Display.getWidth()" in my code? I have tested, but, I can't integrated.

 

 

Jorge Luis Frias B

Leader on Development
BlackBerry/iPhone Technologies
Developer
BBDeveloper
Posts: 3,951
Registered: ‎07-15-2008
My Device: Not Specified

Re: Get width of Screen

The place you where need Screen width call that method.

Use Search. "Accept Solution" If the problem is resolved.
Developer
jlfrias
Posts: 108
Registered: ‎01-29-2009
My Device: BlackBerry 8700g
My Carrier: Tigo

Re: Get width of Screen

Sorry, I don't undertand. Would you explain again?

 

Thanks

Jorge Luis Frias B

Leader on Development
BlackBerry/iPhone Technologies
Developer
mantaker
Posts: 1,477
Registered: ‎12-30-2008
My Device: Torch 9810

Re: Get width of Screen

In your code, instead of widthScreenDevice(), add Display.getWidth()

 

Thanks! 

--
Manimaran Selvan
Co-Founder, Tech Lead,
Equity Markets Research Group
Developer
Rajat_10Sep
Posts: 696
Registered: ‎12-02-2008
My Device: Not Specified

Re: Get width of Screen

Hi,

 

Take 2 public static variables say deviceWidth and deviceHeight and initialize these variables with

   deviceWidth = Display.getWidth() and deviceHeight = Display.getHeight()

 

Initialize these variables inside the constructor of the class which contains main() and then use these variables in your application.

Regards,
Rajat Gupta.
--------------------------------------------------------------------------------
If your problem was get solved then please mark the thread as "Accepted solution" and kudos - your wish