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: 113
Registered: ‎09-30-2009
My Device: Bold 9700

How to set existing field in v5.0 GridFieldManager

[ Edited ]

Hi

 

I am attempting to use a GridFieldManager for 5.0.  I have a 6 x 6 layout, and want to add the manager to the screen and later on update individual 'cells'.  I have tried to 'initialize' each cell by inserting a new labelfield w/ a blank

 

Then later, I try and use set as per:

 

http://www.blackberry.com/developers/docs/5.0.0api/net/rim/device/api/ui/container/GridFieldManager....

 

Which says it replaces the field if its already there.  But I get the following error:

 

java.lang.NullPointerException

 

Code:

 

MachInfoManager = new GridFieldManager(6,6, Field.FIELD_LEFT | Manager.USE_ALL_WIDTH | Manager.NO_VERTICAL_SCROLL);

//code to add labels on row 1

//initialize rest of grid
for (int row = 1; row <= 5; row++) {
for (int col = 0; col <= 5; col++) {
String lbl = ""; //"X";

MachInfoManager.insert(new LabelField(lbl,DrawStyle.LEFT | Field.FIELD_LEFT | Field.NON_FOCUSABLE), row, col);
}
}

//end screen layout


...
//for loop
MachInfoManager.set(new LabelField("X",DrawStyle.LEFT | Field.FIELD_LEFT | Field.NON_FOCUSABL

 

Any ideas?

Developer
Posts: 113
Registered: ‎09-30-2009
My Device: Bold 9700

Re: How to set existing field in v5.0 GridFieldManager

[ Edited ]

Ok, I think I figured this out.  Even though the documentation states:

 

"If the cell is already occupied, the existing field is replaced."

 

It seems to only work (at least for me) if you first delete the cell you want to set.  Can anyone from RIM confirm this?

 

-Scott

Developer
Posts: 113
Registered: ‎09-30-2009
My Device: Bold 9700

Re: How to set existing field in v5.0 GridFieldManager

Ok, I got the set(x,y) function to not throw an exception.  But...

 

I think I have found a bug.  If you have a GridFieldManager, and update fields (either by using delete(x,y) and insert(x,y)  or simply by using set(x,y) then the columns get larger and larger every time you update.

 

I am using a fixed size via setColumnProperty for each column like:

 

GFManager.setColumnProperty(0, GridFieldManager.FIXED_SIZE, 60);
GFManager.setColumnProperty(1, GridFieldManager.FIXED_SIZE, 240);
GFManager.setColumnProperty(2, GridFieldManager.FIXED_SIZE, 60);
GFManager.setColumnProperty(3, GridFieldManager.FIXED_SIZE, 30);
GFManager.setColumnProperty(4, GridFieldManager.FIXED_SIZE, 30);
GFManager.setColumnProperty(5, GridFieldManager.FIXED_SIZE, 30);

 

 

My grid is a 6x6 grid.  I am using the first row as a set of labels (which don't change).

 

Any ideas?

Developer
Posts: 113
Registered: ‎09-30-2009
My Device: Bold 9700

Re: How to set existing field in v5.0 GridFieldManager

Anybody able to replace existing fields in grid manager w/o issues?  If so, please help.

Developer
Posts: 113
Registered: ‎09-30-2009
My Device: Bold 9700

Re: How to set existing field in v5.0 GridFieldManager

[ Edited ]

Bump.  Anyone?  Ideas/suggestions?

 

I have also tried this BB Development Guide for using a grid, which also does not work.

Developer
Posts: 113
Registered: ‎09-30-2009
My Device: Bold 9700

Re: How to set existing field in v5.0 GridFieldManager

Here is a demo project that reproduces the issue.  I am using the BB Bold 9700 simulator (also works same on actual device).

 

Can somebody give it a try and see if they have any insight/ideas?

 

Regards,

Scott

New Contributor
Posts: 2
Registered: ‎07-29-2010
My Device: Blackberry 9550 Storm2
My Carrier: Verizon

Re: How to set existing field in v5.0 GridFieldManager

 

I've been having this exact same problem using LabelFields inside the grid cells.  I've tried everything possible to fix it to no avail. A different post originally said it was fixed by using RichTextFields instead of LabelFields but later posted that it wasn't the answer.

 

I have a 6 x 4 grid and whenever I use the setText() for the label, the grid grows until finally everything to the right of the 1st updated field appears off-screen.  I've tried EVERYTHING I can think of with no success.  Deleted the field and added it back, etc...

 

May have to ditch the grid which really sucks.

 

Did you find any answers?

 

Thanks in advance for any help.

 

Woody

Developer
Posts: 113
Registered: ‎09-30-2009
My Device: Bold 9700

Re: How to set existing field in v5.0 GridFieldManager

I have not solved this yet.  Please vote for the bug/fix here:

 

https://www.blackberry.com/jira/browse/JAVAAPI-1334

 

I worked around this for now by creating 36 fields (for my 6x6 grid) and just call them by name.  Its a ton more code, but it is the only thing I could get to work.

 

Regards,

Scott

New Contributor
Posts: 2
Registered: ‎03-06-2009
My Device: Not Specified

Re: How to set existing field in v5.0 GridFieldManager

Just a note to say I found a solution/workaround for the GridFieldManager's growing field issue that at least worked for me.

 

After changes to the grid I call:

 

        grid.setCellPadding(0);
        grid.setColumnPadding(0);

Maybe the padding values get changed incorrectly (and keep growing) and need to be reset???

Highlighted
Contributor
Posts: 12
Registered: ‎04-16-2012
My Device: Bold 9780
My Carrier: Vodafone

Re: How to set existing field in v5.0 GridFieldManager

you are absolutely right. In 5.0 GridFieldmanager if we set FIXED_WIDTH for any row or column, after each time it's relayout it keep growing unless we specify

 

setCellPadding(0);

 

setColumnPadding(0);

 

setRowPadding(0);

 

And I love this GridFieldManager for it's extremely weird behaviour Smiley Happy