BlackBerryForums.com : Your Number One BlackBerry Community  
   

»Sponsored Links



Closed Thread
 
LinkBack Thread Tools
  (#1 (permalink)) Old
pogi Offline
Knows Where the Search Button Is
 
Posts: 15
Join Date: Sep 2004
Default FieldManagers and Stuff.. - 09-03-2004, 12:57 PM

Ok guys, I need some help on VerticalFieldManagers. I want to do something like this:

-----------------------
This stays on screen
-----------------------
| This section scrolls |
| This section scrolls |
| This section scrolls |
| This section scrolls |
-----------------------
This stays on screen
-----------------------

Does anyone know how to do this? I've been using a MainScreen and just creating a HorizontalFieldManger and adding it using SetStatus for the bottom part, but how would I make the top part stay on the screen? I can't addit using SetTitle because then my title doesn't look nice with the cool gradient.

-Chris
   
Sponsored Links
Please Login or Register to Remove these Advertisements!

  (#2 (permalink)) Old
jbartel Offline
Knows Where the Search Button Is
 
Posts: 17
Join Date: Sep 2004
Default 09-03-2004, 02:14 PM

You need a Screen with 3 VerticalFieldManagers (vfm1, vfm2, vfm3).

Make vfm1 and vfm3 manager that do not scroll.
Make vfm2 a manager that will scroll.

Add the top non-scrolling fields to vfm1:
vfm1.add(field1);
...
vfm1.add(fieldn);

Add the middle scrolling fields to vfm2:
vfm2.add(field1);
...
vfm2.add(fieldn);

Add the bottom non-scrolling fields to vfm3:
vfm3.add(field1);
...
vfm3.add(fieldn);

Add the 3 managers to your screen, starting with the top one:
screen.add(vfm1);
screen.add(vfm2);
screen.add(vfm3);
   
  (#3 (permalink)) Old
pogi Offline
Knows Where the Search Button Is
 
Posts: 15
Join Date: Sep 2004
Default 09-03-2004, 02:44 PM

Quote:
You need a Screen with 3 VerticalFieldManagers (vfm1, vfm2, vfm3).

Make vfm1 and vfm3 manager that do not scroll.
Make vfm2 a manager that will scroll.
When I do this it makes the whole screen scroll, not just the middle part.
   
  (#4 (permalink)) Old
jbartel Offline
Knows Where the Search Button Is
 
Posts: 17
Join Date: Sep 2004
Default 09-03-2004, 02:48 PM

then you need to add the NO_VERTICAL_SCROLL style flag to your screen
   
  (#5 (permalink)) Old
pogi Offline
Knows Where the Search Button Is
 
Posts: 15
Join Date: Sep 2004
Default 09-03-2004, 06:27 PM

I added the NO_VERTICAL_SCROLL style flag to my screen, and now all the contents of the screen just flow off of it without any scrolling or scrollbars. Any other ideas?
   
  (#6 (permalink)) Old
berry_apps Offline
Thumbs Must Hurt
 
Posts: 52
Join Date: Aug 2004
Default 09-05-2004, 03:21 PM

hmm I don't belive you can do something like that? You can however use the title and status bar on the main screen.
   
  (#7 (permalink)) Old
eradis Offline
Talking BlackBerry Encyclopedia
 
Posts: 221
Join Date: Sep 2004
Model: 8700r
Carrier: Rogers
Default 09-05-2004, 07:46 PM

If you use the Graphics "clipping" functionality you should be able to do this very easily.
   
  (#8 (permalink)) Old
giesen Offline
Knows Where the Search Button Is
 
giesen's Avatar
 
Posts: 26
Join Date: Mar 2005
Model: 8700R
Carrier: Rogers
Default 04-12-2005, 03:02 AM

Did anyone ever figure this out? I'm trying to do the exact same thing as well.
   
  (#9 (permalink)) Old
leoshaw Offline
New Member
 
Posts: 12
Join Date: Aug 2005
Model: SK65
Carrier: T-mobile
Default 10-24-2005, 08:18 AM

Has anyone cracked this yet?
   
  (#10 (permalink)) Old
fbrimm Offline
Thumbs Must Hurt
 
Posts: 121
Join Date: Aug 2005
Model: 8830
Carrier: Verizon
Default 10-25-2005, 07:39 AM

The easiest solution is to use the default MainScreen that gives you a title area at the top and a status area at the bottom. You may be limited to a single line/field in each.

I've actually created a screen that acts like a spreadsheet. The title remains fixed at the top. I have a second area of the screen that is the heading above each column, which does not scroll vertically but allows horizontal scrolling if there are more columns than can be displayed. The next section of the screen contains all the individual "cells". At the bottom I use the status line that remains fixed at the bottom.

Here's how the various managers are set up:

-----------MainScreen-------------
Title
------Horizontal Field Manager------
|--VFM1--|--VFM2--|--VFM3--|... {as many columns as you want}
| heading | heading | heading |...
| field | field | field |...
| ... | ... | ... |...
|---------|---------|---------|...
-----------------------------------
Status
-----------------------------------

The Vertical Field Managers are the only managers with Vertical Scroll allowed. The result is the Title is fixed at the top of the screen and the Status is fixed at the bottom of the screen, the rest of the screen can scroll vertically if there are more "rows" than can be displayed, and can scroll horizontally if there are more "columns" than can be displayed.

Hope that helps. Its kind of difficult to illustrate with just text.
   
  (#11 (permalink)) Old
ecarmody Offline
Thumbs Must Hurt
 
Posts: 80
Join Date: Apr 2005
Location: Portland, OR., USA
Model: 8100
Carrier: Cingular
Default 10-28-2005, 02:46 PM

hey fbrimm ... I like your approach. Can you tell me, is there a way to specify the position and/or the height/width dimensions of the manager?

If your add multiple vertical managers, how are you controlling how wide they are?

Thanks,
Eric
   
  (#12 (permalink)) Old
fbrimm Offline
Thumbs Must Hurt
 
Posts: 121
Join Date: Aug 2005
Model: 8830
Carrier: Verizon
Default 10-31-2005, 10:13 AM

Eric,

I just let the width of my fields adjust themselves based on the data being displayed. That way, nothing is cut off if I made the width too small, and there's no wasted space if I made the width too large.

Along the way, I've also played around with creating a custom field by passing an additional parameter to set a fixed width. To make this work properly, you also have to specify that the field will display using a mono spaced font (ie, system).

Rather than try to explain it all, take a look at the following code. The _labelWidth and setExtent call is what makes this work. I started with the CustomFieldButton example and came up with this.

Code:
public class CustomButtonField extends Field implements DrawStyle {
    private String _label;
    private String text = "W";
    private int _shape;
    private Font _font;
    private int _labelHeight;
    private int _labelWidth;
    private long _style;
    
    // Constructs a rectangular button with specified label, shape, and style
    public CustomButtonField(String label, long style, int fixWidth) {
        super(style);
        _style = style;
        _label = label;
        _font = getFont();
        _labelHeight = _font.getHeight();
        
        if (fixWidth == 0) {
            _labelWidth = _font.getAdvance(_label);
        } else {
            for (int i=1; i<fixWidth; i++) {
                text = text + "W";
            }
            _labelWidth = _font.getAdvance(text);
        }
    }
    
    /* Method that draws the focus indicator for this button and 
     * inverts the inside region of the shape.
     */
    protected void drawFocus(Graphics graphics, boolean on) {
        graphics.invert(1, 1, getWidth() - 2, getHeight() - 2);
    }
    
    /* Returns the label. */
    public String getLabel() {
        return _label;
    }
    
    /* Sets the label. */
    public void setLabel(String label) {
        _label = label;
        _labelWidth = _font.getAdvance(_label);

        updateLayout();
    }
    
    /* Retrieves the preferred width of the button. */
    public int getPreferredWidth() {
        return _labelWidth + 8;
    } 

    /* Retrieves the preferred height of the button. */
    public int getPreferredHeight() {
        return _labelHeight + 4;
    }

    /**
     * Lays out this button's contents.
     * This field's manager invokes this method during the layout
     * process to instruct this field to arrange its contents, given an 
     * amount of available space.
     **/
    protected void layout(int width, int height) {
        // Update the cached font in case it has been changed.
        _font = getFont();
        _labelHeight = _font.getHeight();

        // Calculate width.
        width = Math.min( width, getPreferredWidth() );

        // Calculate height.
        height = Math.min( height, getPreferredHeight() );

        // Set dimensions.
        setExtent( width, height );
    }

    /*
     * Redraws this button. The field’s manager invokes this method during the 
     * repainting process to instruct this field to repaint itself
     */
    protected void paint(Graphics graphics) {
        int textX, textY, textWidth;
        int w = getWidth();

        //Use light grey lines to draw border of rectangle
        int orgColor = graphics.getColor();
        graphics.setColor(0x007f7f7f);

        graphics.drawRect(0, 0, w, getHeight());
        textX = 4;
        textY = 2;
        textWidth = w - 6;
                
        //Return original color
        graphics.setColor(orgColor);

        graphics.drawText(_label, textX, textY, 
            (int)( _style & ( DrawStyle.ELLIPSIS | DrawStyle.HALIGN_MASK )), 
            textWidth );
     }
}
Again, to set a fixed width I mostly borrowed from the CustomButtonField example and added the section to set the width of a number of W characters as the extent.

Hope this helps.
   
  (#13 (permalink)) Old
ecarmody Offline
Thumbs Must Hurt
 
Posts: 80
Join Date: Apr 2005
Location: Portland, OR., USA
Model: 8100
Carrier: Cingular
Default 11-02-2005, 11:57 AM

Thanks, fbrimm, that gives me some good ideas.

I was actually thinking of width in terms of pixels whereas your example is based on characters. That's good too, however, it appears to be easily modifiable in the FOR loop by building the text string and checking the getAdvance() while it is <= fixWidth in pixels; or even based on a percentage of screen.

Cheers,
Eric
   
  (#14 (permalink)) Old
leoshaw Offline
New Member
 
Posts: 12
Join Date: Aug 2005
Model: SK65
Carrier: T-mobile
Default 11-07-2005, 05:01 AM

Thanks for a really helpful reply fbrimm, the code for your custom Field component was particularly useful.

Just for reference, the original problem that I was having (I only wanted a portion of the screen to scroll vertically, while the rest stayed put) was solved by subclassing MainScreen, calling super(Manager.NO_VERTICAL_SCROLL) in the constructor, and adding a VerticalFieldManager with Manager.VERTICAL_SCROLL to contain the ObjectListField where I wanted scrolling to occur. Not sure how I missed this first time around - I thought I'd tried it and it didn't work but it's fine.

Strangely, the Status field doesn't render on a 7100t, despite appearing as expected in the emulator, has anyone encountered this on other devices?

Cheers,

Leo
   
Closed Thread


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