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: 1,006
Registered: ‎05-22-2009
My Device: Not Specified

How To make the HorizontalFieldManager Width a constant One

can anyone say,how to change HorizontalFieldManager Width

 

i tried by overriding the int getPreferredWidth()\

 

but i didn't work any suggestions

 

thanks

Developer
Posts: 984
Registered: ‎02-10-2009
My Device: Not Specified

Re: How To make the HorizontalFieldManager Width a constant One

You have to override sublayout() method. Like:

 

HorizontalFieldManager manager = new HorizontalFieldManager() { //define width public int getPreferredWidth() { return Display.getWidth(); } //define height public int getPreferredHeight() { return 100; } protected void sublayout( int maxWidth, int maxHeight ) { super.sublayout(getPreferredWidth(), getPreferredHeight()); setExtent(getPreferredWidth(), getPreferredHeight()); } };

 

Regards

Bikas

 

New Developer
Posts: 1
Registered: ‎09-16-2009
My Device: Not Specified

Re: How To make the HorizontalFieldManager Width a constant One

[ Edited ]

 

The bikas' sollution makes the fixed-height HorizontalFieldManager for me. So when I add a LabelField with a long text I see the only one line inside. The following sollution makes HorizontalFieldManager with constant width and height corresponding to the content height:


public int getPreferredWidth() {
return getScreen().getWidth();
}

protected void sublayout( int maxWidth, int maxHeight ) {
super.sublayout(getPreferredWidth(),
maxHeight);
XYRect rec = getExtent();
setExtent(getPreferredWidth(), rec.height);
}

Please correct me if something wrong in my sollution.

 

 

Regards,

Dmitry

Message Edited by mallrat on 09-16-2009 01:56 PM
Developer
Posts: 37
Registered: ‎05-27-2010
My Device: 9700 Storm

How To make HorizontalFieldManager contatining more Edit Fields?

[ Edited ]

Hi,

 

I've been trying to accommodate 2 EditFields and a ButtonField in a HorizontalFieldManager. I added the following code, but it's showing RunTimeException (Uncaught Exception, pushModalScreen called by a non-event thread)

 

fieldSortName = new EditField("SortName: ", "", 10, Field.FIELD_HCENTER|Field.FOCUSABLE);
fieldCustNo = new EditField("CustNo:", "", 5, Field.FIELD_HCENTER|Field.FOCUSABLE);
buttonBrowse1 = new ButtonField("..", Field.FOCUSABLE | Field.FIELD_HCENTER);
   
HorizontalFieldManager horsnMgr = new HorizontalFieldManager(Field.FIELD_HCENTER)
{
     protected void sublayout(int maxWidth, int maxHeight)
     {
  layoutChild(fieldSortName, fieldSortName.getPreferredWidth(), fieldSortName.getPreferredHeight());
  setPositionChild(fieldSortName, 0, 0);
  layoutChild(buttonBrowse1, buttonBrowse1.getPreferredWidth(), buttonBrowse1.getPreferredHeight());
  setPositionChild(buttonBrowse1, maxWidth/2, 0);
  layoutChild(fieldCustNo, fieldCustNo.getPreferredWidth(), fieldCustNo.getPreferredHeight());
  setPositionChild(fieldCustNo, maxWidth - fieldCustNo.getWidth(), 0);
  setExtent(maxWidth, maxHeight);
  }
};
horsnMgr.add(fieldSortName);
horsnMgr.add(buttonBrowse1);
horsnMgr.add(fieldCustNo); 

Can anyone help? 

 

--------------------------------------------------------------------------------------
Justin Aloor

Feel free to press the Kudos Button to thank the user who helped you.
Please mark posts as solved if you found a solution.
Developer
Posts: 19,636
Registered: ‎07-14-2008
My Device: Not Specified

Re: How To make HorizontalFieldManager containing more Edit Fields?

Typically with new problems, the recommended approach is to start a new Thread.

 

And since the code displayed does not include a pushModalScreen, I suspect the problem is not going to be found by looking at the way you add more Edit Fields to your HFM.

 

With respect to your actual error - pushModalScreen called by a non-event thread - this is a fairly common error and one that I'm sure other Threads discuss.  So please check the forum for other entries that might help you with this problem, before starting a new Thread. 

 

Once you are sure that this is not just a repeat of a problem that has already been resolved in the forum, start a new Thread, and show us the failing code.

Developer
Posts: 37
Registered: ‎05-27-2010
My Device: 9700 Storm

Re: How To make HorizontalFieldManager containing more Edit Fields?

Hi,

 

Thanks for your reply. The Runtime Exception was due to some other issues. That's OK now.

But, with this code, I can see only a part of  button and the second EditField is not visible.

What are the criteria for setting the attributes for layoutChild and setpositionChild?

--------------------------------------------------------------------------------------
Justin Aloor

Feel free to press the Kudos Button to thank the user who helped you.
Please mark posts as solved if you found a solution.
Developer
Posts: 19,636
Registered: ‎07-14-2008
My Device: Not Specified

Re: How To make HorizontalFieldManager containing more Edit Fields?

[ Edited ]

New Thread for a new problem please.

 

Edit:Ignore, misread....  Sorry

Highlighted
Developer
Posts: 2,268
Registered: ‎07-08-2009
My Device: various
My Carrier: various

Re: How To make the HorizontalFieldManager Width a constant One

The solution by mallrat is almost correct.  However, in general you should honor your parent manager's request to stay within the passed (maxWidth and maxHeight) limits.  Something like this is much closer to the "clean" BB programming:

 

	public int getPreferredWidth() {
		return getScreen().getWidth();
	}

	protected void sublayout( int maxWidth, int maxHeight ) {
                int myWidth = Math.min(maxWidth, getPreferredWidth);
                int myHeight = maxHeight;
		super.sublayout(myWidth, myHeight);
		setExtent(myWidth, myHeight);
	}

 Of course, myHeight in this example is completely unnecessary, but keep that in mind as an example.  One day you'll decide you need to mandate your own height as well...

 

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