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
eicheled
Posts: 77
Registered: ‎04-01-2011
My Device: Bold 9700
My Carrier: Rogers
Accepted Solution

Popup layout problem

I've got a popup, and for some reason I can't get the objects I'm laying out inside of it to use all the real estate available.

 

Here is the code:

 

public class PersonBalancePopup extends PopupScreen {

	private final static int _Width = 225;
	private final static int _Height = 150;
	private final static int _X = (Display.getWidth() - _Width) >> 1;
	private final static int _Y = (Display.getHeight() - _Height) >> 1;
	private ButtonField saveButton;	
	private ButtonField cancelButton;
	private HorizontalFieldManager hfm;
	
	public PersonBalancePopup(Person p) {		
		super(new VerticalFieldManager(VerticalFieldManager.USE_ALL_WIDTH));
		hfm = new HorizontalFieldManager(HorizontalFieldManager.USE_ALL_WIDTH);
		saveButton = new ButtonField(Constants.SAVE);
		cancelButton = new ButtonField(Constants.CANCEL);
		hfm.add(saveButton);
		hfm.add(cancelButton);

		add(hfm);
	}
	
	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, Constants.POPUP_Y);
	}
}

 

Anything refered to by Constants.* are just that, predefined constants.

 

Here is what it looks like:

 

popup.jpg

 

 

I don't understand why the buttons won't use all the available width?

 

Suggestions appreciated!

 

 

 

Please use plain text.
Developer
eicheled
Posts: 77
Registered: ‎04-01-2011
My Device: Bold 9700
My Carrier: Rogers

Re: Popup layout problem

FYI, the label on the second button should contain the string "Cancel"

 

Please use plain text.
Developer
eicheled
Posts: 77
Registered: ‎04-01-2011
My Device: Bold 9700
My Carrier: Rogers

Re: Popup layout problem

If anyone can offer a kick in the right direction, I'd appreciate it very much.

 

I've followed examples (such as this one)

 

http://supportforums.blackberry.com/t5/Java-Development/Popup-Screen-issues/td-p/478607

 

But I don't get the results I want. Here is the image of what this example renders as:

 

popup2.jpg

 

Even though everything seems to be aligned with each other, it certainly isn't aligned within the boundaries of the popup.

 

Why is there all that unused real estate on the right hand side?

 

 

Please use plain text.
Developer
alishaik786
Posts: 285
Registered: ‎08-26-2011
My Device: 9900
My Carrier: Not Specified

Re: Popup layout problem

[ Edited ]

Remove these statements from your code then you get.

 

public void sublayout(int width, int height)
{
	super.sublayout(getPreferredWidth(), Integer.MAX_VALUE);
	setExtent(getPreferredWidth(), getPreferredHeight());
	setPosition(_X, Constants.POPUP_Y);
}

I can get like this:

2011-10-05_1119.png

 =================================================================================

Feel free to click THUMB Symbol which is right side.

=================================================================================
Feel free to click LIKE button if the solution helps you;
--
Regards,

ALI SHAIK.
Please use plain text.
Developer
arkadyz
Posts: 2,268
Registered: ‎07-08-2009
My Device: various
My Carrier: various

Re: Popup layout problem

If you need to override sublayout in order to setPosition, don't play with width and height passed to you, and don't setExtent on your own. Just do it like this:

}

protected void sublayout(int width, int height)
{
	super.sublayout(width, height);
	setPosition(_X, Constants.POPUP_Y); 
----------------------------------------------------------
please click 'Accept Solution' on posts that provide the solution to the question you've posted. Don't say "Thanks", press 'Like' button instead!
Please use plain text.
Developer
laurentC
Posts: 266
Registered: ‎02-05-2010
My Device: Blackberry Z10
My Carrier: Bouygues Telecom

Re: Popup layout problem

Maybe replace :

 

saveButton = new ButtonField(Constants.SAVE);
cancelButton = new ButtonField(Constants.CANCEL);

with

 

saveButton = new ButtonField(Constants.SAVE ,ButtonField.CONSUME_CLICK  | ButtonField.FIELD_HCENTER);

saveButton.setChangeListener(this);
cancelButton = new ButtonField(Constants.CANCEL,ButtonField.CONSUME_CLICK  | ButtonField.FIELD_HCENTER);

cancelButton.setChangeListener(this);

 

and don't override getPreferredWidth, getPreferredHeight and sublayout

Twitter : @LaurentKP
My apps
Please use plain text.
Developer
eicheled
Posts: 77
Registered: ‎04-01-2011
My Device: Bold 9700
My Carrier: Rogers

Re: Popup layout problem

Thanks everyone for their replies!

 

@arkadyz - That's what I'm looking for, I need to maintain the ability to set the position.

 

I don't know if you can answer this, but why do all the examples I found contain that code, and produce the results that I posted above? Is that 'normal'?

 

Please use plain text.
Developer
arkadyz
Posts: 2,268
Registered: ‎07-08-2009
My Device: various
My Carrier: various

Re: Popup layout problem

There are many great examples on the Internet, but there are also hideously bad ones. Some of the bad stuff get copied mindlessly because people don't have time to look through the code and check for errors. One of the worst pieces of code which are not even immediately obviously wrong (at least do not produce outrageous visible results) is getManager().invalidate() inside paint() - it produces a kind of an infinite loop, draining CPU (and battery) like crazy. Still, I've seen it in several places on some respectable sites including blackberry.com as well.

 

I found that very few people pay enough attention to all this layout/sublayout stuff let alone try to understand how it works...

----------------------------------------------------------
please click 'Accept Solution' on posts that provide the solution to the question you've posted. Don't say "Thanks", press 'Like' button instead!
Please use plain text.