BlackBerry Forums Support Community
              

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

Please Login to Remove!

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 ?
Offline  
Old 06-23-2008, 11:00 AM   #2
richard.puckett
Talking BlackBerry Encyclopedia
 
richard.puckett's Avatar
 
Join Date: Oct 2007
Location: Seattle, WA
Model: 9020
PIN: N/A
Carrier: T-Mobile
Posts: 212
Default

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.
Offline  
Old 06-24-2008, 02:00 AM   #3
greg_orille
Knows Where the Search Button Is
 
Join Date: Jun 2008
Model: 8310
PIN: N/A
Carrier: Developper
Posts: 43
Default

Exactly that.

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

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;
    }
}
Offline  
Old 06-24-2008, 09:52 AM   #5
greg_orille
Knows Where the Search Button Is
 
Join Date: Jun 2008
Model: 8310
PIN: N/A
Carrier: Developper
Posts: 43
Default

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, 24 views)
Offline  
Old 06-24-2008, 10:43 AM   #6
richard.puckett
Talking BlackBerry Encyclopedia
 
richard.puckett's Avatar
 
Join Date: Oct 2007
Location: Seattle, WA
Model: 9020
PIN: N/A
Carrier: T-Mobile
Posts: 212
Default

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.
Offline  
Old 06-24-2008, 02:18 PM   #7
greg_orille
Knows Where the Search Button Is
 
Join Date: Jun 2008
Model: 8310
PIN: N/A
Carrier: Developper
Posts: 43
Default

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.
Offline  
Old 06-25-2008, 03:51 AM   #8
greg_orille
Knows Where the Search Button Is
 
Join Date: Jun 2008
Model: 8310
PIN: N/A
Carrier: Developper
Posts: 43
Default

Up :(
Offline  
Closed Thread



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

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


Radiomatic Flo-One Beta Radio-Chromatography Detector A-500 Model A525 [E2FL] picture

Radiomatic Flo-One Beta Radio-Chromatography Detector A-500 Model A525 [E2FL]

$245.00



Mitsubishi FR-A540-0.75K-NA AC DRIVE INVERTER 1 HP 380-480 VAC 50/60 HZ 4.1 AMP  picture

Mitsubishi FR-A540-0.75K-NA AC DRIVE INVERTER 1 HP 380-480 VAC 50/60 HZ 4.1 AMP

$649.99



Mitsubishi A500 Variable Freq. Drive VFD AC Inverter 480V 3 PH 6.7A 3 HP Max picture

Mitsubishi A500 Variable Freq. Drive VFD AC Inverter 480V 3 PH 6.7A 3 HP Max

$299.99



*PARTS/REPAIR* Mitsubishi FR-A520-5.5K-NA A500vInverter In: 35.5A 3Ph Out: 10Hp picture

*PARTS/REPAIR* Mitsubishi FR-A520-5.5K-NA A500vInverter In: 35.5A 3Ph Out: 10Hp

$750.00



A54MA55B  BC186A413G52 Drive board for A500/F540 series 55KW picture

A54MA55B BC186A413G52 Drive board for A500/F540 series 55KW

$350.00



Mitsubishi Inverter A500 50HP FR-A540-37K-EC 37kW 71A picture

Mitsubishi Inverter A500 50HP FR-A540-37K-EC 37kW 71A

$2970.00







Copyright © 2004-2016 BlackBerryForums.com.
The names RIM © and BlackBerry © are registered Trademarks of BlackBerry Inc.