BlackBerryForums.com : Your Number One BlackBerry Community      

»Sponsored Links



Reply
 
LinkBack Thread Tools
  (#1 (permalink)) Old
greg_orille Offline
Knows Where the Search Button Is
 
Posts: 43
Join Date: Jun 2008
Model: 8310
PIN: N/A
Carrier: Developper
Default Problem with Label and dynamic size. - 06-23-2008, 08:20 AM

Hi,

I'm building a grid, and i want to use a class to create a custom Label adapted to a size.

i use :

class SizeableLabelField extends LabelField {

SizeableLabelField(String text) {
super(text);
}

public int getPreferredWidth() {
return getFont().getAdvance(getText());
}

protected void layout(int width, int height) {
width = getPreferredWidth();
height = super.getPreferredHeight();
super.layout(width, height);
super.setExtent(width, height);
}
}

but the text is cutted :(

Any idea to create a grid with a column adapted to the biggest text ?
   
Reply With Quote
Sponsored Links
Please Login or Register to Remove these Advertisements!

  (#2 (permalink)) Old
richard.puckett Offline
Talking BlackBerry Encyclopedia
 
richard.puckett's Avatar
 
Posts: 212
Join Date: Oct 2007
Location: Seattle, WA
Model: 8800
PIN: N/A
Carrier: AT&T
Default 06-23-2008, 11:00 AM

It sounds like what you want is a Manager function (if I'm understanding correctly).

Say you have a Manager composed of some text fields - say, a VerticalFieldManager which represents a column in a grid. Here's some pseudocode which shows approximately how to set a column to the greatest width of all contained fields. HTH.

Code:
protected void sublayout(int width, int height) {
   int maxWidth = 0;
   int yOffset = 0;
   int fieldCount = getFieldCount();

   for (int i = 0; i < fieldCount; i++) {
      Field field = getField(i);
      layoutChild(field, width, height);
      setPositionChild(field, 0, yOffset);
      yOffset += field.getHeight();
      maxWidth = Math.max(maxWidth, field.getWidth();
   }

   setExtent(maxWidth, yOffset);
}


Do your homework and know how to ask a good question.
   
Reply With Quote
  (#3 (permalink)) Old
greg_orille Offline
Knows Where the Search Button Is
 
Posts: 43
Join Date: Jun 2008
Model: 8310
PIN: N/A
Carrier: Developper
Default 06-24-2008, 02:00 AM

Exactly that.

So what i need to do. A HorizontalFieldManager, which contains, VerticalFieldManager ?
   
Reply With Quote
  (#4 (permalink)) Old
greg_orille Offline
Knows Where the Search Button Is
 
Posts: 43
Join Date: Jun 2008
Model: 8310
PIN: N/A
Carrier: Developper
Default 06-24-2008, 04:05 AM

Thanks, It works GREAT but in order to have a powerfull GRID, i want to have an Horizontal and Vertical scrollbar only on the grid. I don't want scrollbar in the mainscreen.

My GRID Class :

Code:
public class Grid {

    private int columns;
    private int rows;
    private HorizontalFieldManager view;

    public Grid(Manager m, int c, int r) {
        
        // CONTAINER
        view = new HorizontalFieldManager();
        
        columns = c;
        rows = r;

        // Counter CCOLUMNS
        int i = 0;
        // Counter ROWS
        int j = 0;

        // FILL DATA
        for (i = 0; i < columns; i++) {

            // Create Column.
            Column myColumns = new Column(VerticalFieldManager.NO_HORIZONTAL_SCROLL | VerticalFieldManager.NO_VERTICAL_SCROLL);

            // Create Lines in Colomn.
            for (j = 0; j < rows; j++) {
                if (j != 2) {
                    LabelField label = new LabelField("-",Field.FIELD_HCENTER);
                    myColumns.add(label);
                } else {
                    LabelField label = new LabelField("AAA",Field.FIELD_HCENTER);
                    myColumns.add(label);
                }
  
            }
            view.add(myColumns);
        }

    }

    public Field getField(int c,int r){
        return ((VerticalFieldManager)view.getField(c)).getField(r);
    }
    
    public HorizontalFieldManager getView() {
        return view;
    }

    public void setView(HorizontalFieldManager view) {
        this.view = view;
    }
}
   
Reply With Quote
  (#5 (permalink)) Old
greg_orille Offline
Knows Where the Search Button Is
 
Posts: 43
Join Date: Jun 2008
Model: 8310
PIN: N/A
Carrier: Developper
Default 06-24-2008, 09:52 AM

i have also this problem :

I have used your code to have a Column adapted to the biggest labelField.

But i have a problem, if i use colors for the column... field... there is a space.

We can't force to change the width of all labels in order to have all the label with the same width ?

See the image.

Thanks you for you help
Attached Images
File Type: jpg Presse Papier-1.jpg (25.7 KB, 12 views)
   
Reply With Quote
  (#6 (permalink)) Old
richard.puckett Offline
Talking BlackBerry Encyclopedia
 
richard.puckett's Avatar
 
Posts: 212
Join Date: Oct 2007
Location: Seattle, WA
Model: 8800
PIN: N/A
Carrier: AT&T
Default 06-24-2008, 10:43 AM

There's quite a bit you can do with laying out standard fields - it just involves overriding the right methods, generally the (sub)layout methods. I don't quite understand what I'm seeing in your screenshot versus what you're trying to do. Maybe a little more explanation of what you're trying to achieve?


Do your homework and know how to ask a good question.
   
Reply With Quote
  (#7 (permalink)) Old
greg_orille Offline
Knows Where the Search Button Is
 
Posts: 43
Join Date: Jun 2008
Model: 8310
PIN: N/A
Carrier: Developper
Default 06-24-2008, 02:18 PM

Sorry for my bad english ;)

So i will try to explain.

With you code, i succeded to get a column adapted to the biggest label.

the problem :

if you set a backgroundcolor to the VerticalFieldManager (in my case : AQUA)

When you have a field smaller than the column (for example the column's header "NOM" and you set a background (YELLOW) the background dosn't fill all the width of the column (On the right of this label, we can see the background of the verticalFieldManager)

Do you understand ?

Thanks you for your help.
   
Reply With Quote
  (#8 (permalink)) Old
greg_orille Offline
Knows Where the Search Button Is
 
Posts: 43
Join Date: Jun 2008
Model: 8310
PIN: N/A
Carrier: Developper
Default 06-25-2008, 03:51 AM

Up :(
   
Reply With Quote
Reply


Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On






Copyright © 2004-2008 BlackBerryNews.com, BlackBerryFAQ.com, BlackBerryForums.com.
The names RIM © and BlackBerry © are registered Trademarks of Research In Motion Limited.
Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
SEO by vBSEO 3.0.1