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
Posts: 62
Registered: ‎01-22-2010
My Device: BOLD 9700
My Carrier: Globe
Accepted Solution

Popup Screen issues

[ Edited ]

I've already tried using the search tool and googled my whole day but I can't seem to find the answer to this two problems.

 

1. I'm trying to position my popup screen in the middle of the screen. But as you can see in the image below it's nowhere near the center.

 

2. I'm trying to center my two buttons in the middle of the popup screen using a verticalfieldmanager but somehow it's basing it's position on width I don't know what.

 

here's the code:

 

 

private final static int _Width = 200;
private final static int _Height = 200;
private final static int _X = (Display.getWidth() - _Width) >> 1;
private final static int _Y = (Display.getHeight() - _Height) >> 1;
public class NetworkSettingScreen extends PopupScreen
{

public NetworkSettingScreen()
{
super( new VerticalFieldManager());
LabelField lf = new LabelField("Network Settings", DrawStyle.HCENTER);
SeparatorField sf = new SeparatorField();
CheckboxField cbf1 = new CheckboxField(" WiFi", true);
CheckboxField cbf2 = new CheckboxField(" GPRS/Edge/3G", true);

VerticalFieldManager vfm = new VerticalFieldManager(HorizontalFieldManager.FIELD_HCENTER);
ButtonField bf1 = new ButtonField("Save", DrawStyle.HCENTER);
ButtonField bf2 = new ButtonField("Cancel", DrawStyle.HCENTER);
vfm.add(bf1);
vfm.add(bf2);

//add UI components to Pop-up screen
add(lf);
add(sf);
add(cbf1);
add(cbf2);
add(vfm);
}

public void sublayout(int width, int height)
{
super.sublayout(width, height);
setExtent(_Width, _Height);
setPosition(_X, _Y);
}
}//end of class

 

 

 

http://i55.photobucket.com/albums/g152/chengbang69/screenshot.jpg

 

any help would be much appreciated

Developer
Posts: 1,807
Registered: ‎04-28-2009
My Device: Z10 (STL100-4)-10.3.2.858, Z10 (STL100-3)-10.3.1.2576, Z30 (STA100-5)-10.3.1.2582, Passport (SQW100-1)-10.3.1.2576, PlayBook (16GB)-2.1.0.1917
My Carrier: Verizon

Re: Popup Screen issues

Please post a external link to the image because it is not viewable to the general public.

---Spends time in #blackberrydev on freenode (IRC)----
Three simple rules:
1. Please use the search bar before making new posts.
2. "Like" posts that you find helpful.
3. If a solution has been found for your post, mark it as solved.
--I code too much. Well, too bad.
Developer
Posts: 62
Registered: ‎01-22-2010
My Device: BOLD 9700
My Carrier: Globe

Re: Popup Screen issues

[ Edited ]

thanks rcmaniac25 for pointing that out

Developer
Posts: 62
Registered: ‎01-22-2010
My Device: BOLD 9700
My Carrier: Globe

Re: Popup Screen issues

bump

Developer
Posts: 110
Registered: ‎10-22-2009
My Device: 9700
My Carrier: ChinaMobile

Re: Popup Screen issues

if u wanna a center popupscreen , why u re-defined ? the default popupscreen is aligned from center.

private final static int _Width = 200;
private final static int _Height = 200;
Best Regards,
Tiandi
www.tiandiyoyo.com
Developer
Posts: 467
Registered: ‎07-16-2009
My Device: Z10 LE
My Carrier: Vodafone NL

Re: Popup Screen issues

Try this:

 

public void sublayout(int width, int height)
{
	super.sublayout(_Width, _Height);//instead of width and height
	setExtent(_Width, _Height);//here is another problem			
	setPosition(_X, _Y);
}

 

 

But it will have one more issue:

when you do setExtent popup window gets some space for margins. That's why the best will be calling something next:

 

 super.sublayout(_Width + hMargin, _Height + vMargin);

 

But it really hard to find this value.

Highlighted
Developer
Posts: 43
Registered: ‎09-28-2009
My Device: Not Specified

Re: Popup Screen issues

Hey chengbang69,

 

I have modified your code to achieve the desired results,

 

 

final class NetworkSettingScreen extends PopupScreen
{
	private final static int _Width = 200;
	private final static int _Height = 200;
	private final static int _X = (Display.getWidth() - _Width) >> 1;
	private final static int _Y = (Display.getHeight() - _Height) >> 1;

public NetworkSettingScreen()
{
	super( new VerticalFieldManager());
	LabelField lf = new LabelField("Network Settings", LabelField.FIELD_HCENTER);
	SeparatorField sf = new SeparatorField();		
	CheckboxField cbf1 = new CheckboxField(" WiFi", true);
	CheckboxField cbf2 = new CheckboxField(" GPRS/Edge/3G", true);

	VerticalFieldManager vfm = new VerticalFieldManager(VerticalFieldManager.FIELD_HCENTER);
	ButtonField bf1 = new ButtonField("Save", ButtonField.FIELD_HCENTER);
	ButtonField bf2 = new ButtonField("Cancel", ButtonField.FIELD_HCENTER);
	vfm.add(bf1);
	vfm.add(bf2);
		
	//add UI components to Pop-up screen
	add(lf);
	add(sf);
	add(cbf1);
	add(cbf2);
	add(vfm);
}
public int getPreferredWidth() {
	return _Width;
}
public int getPreferredHeight() {
	return _Height;
}

public void sublayout(int width, int height)
{
	super.sublayout(getPreferredWidth(), Integer.MAX_VALUE);
	setExtent(getPreferredWidth(), getPreferredHeight());
	setPosition(_X, _Y);
}
}//end of class

 

The reason you have to override getPreferredHeight() and getPreferredWidth() is due to all the subcalls and sublayouts that actually occur when you call super.sublayout. It will then use the "default" screen layout values or getPreferredWidth/Height.

 

 

Just a friendly recommendation as well, setting the size of a screen to a static value is only efficient if you also control the size of the font, currently if the user has a above average font size some of the text will not be seen, so technically the most efficient way is to have the JVM manage the resizing/scaling itself, this can be done by simply using the same code as I have posted above, however removing the override on sublayout, the width will be slightly bigger than you have defined but at least you will not run into any unknowns.

 

Hope this helps,

 

Regards

 

Andre

Developer
Posts: 62
Registered: ‎01-22-2010
My Device: BOLD 9700
My Carrier: Globe

Re: Popup Screen issues

that actually did the trick. Learned something new. Thanks andre_impi

Developer
Posts: 173
Registered: ‎06-11-2009
My Device: Not Specified

Re: Popup Screen issues

[ Edited ]

Oops, deleted.

BTW, is  it possible to delete the post?