10-02-2011 09:49 PM
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:
I don't understand why the buttons won't use all the available width?
Suggestions appreciated!
Solved! Go to Solution.
10-02-2011 09:50 PM
FYI, the label on the second button should contain the string "Cancel"
10-05-2011 01:38 AM
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-Develo
But I don't get the results I want. Here is the image of what this example renders as:
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?
10-05-2011 01:48 AM - edited 10-05-2011 01:51 AM
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:
=================================================
Feel free to click THUMB Symbol which is right side.
10-05-2011 09:31 AM
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);
10-05-2011 10:00 AM
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_C
cancelButton.setChangeListener(this);
and don't override getPreferredWidth, getPreferredHeight and sublayout
10-08-2011 03:02 PM
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'?
10-11-2011 10:47 AM
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...