BlackBerry Forums Support Community
              

Closed Thread
 
Thread Tools
Old 05-21-2008, 12:24 AM   #1
Pan_magically
Knows Where the Search Button Is
 
Join Date: Apr 2008
Model: 8100
PIN: N/A
Carrier: Hong Kong CSL
Posts: 18
Wink Alpha value of color not working in paint()

Please Login to Remove!

Trying to display a hovering label on top of my ListField. The Label should be a round-rect and has a semi-transparent black bgcolor. I got the label and text to display and everything, but the bgcolor is solid black. The idea is that the hovering label will appear on top of the items in ListField.


here is my code
Code:
public class MyListField extends ListField {


    protected void paint(Graphics g){
        super.paint(g);
        if(this.getSize() > 0)        
            this.paintFloatingText(g);
    }

    protected int getVerticalScroll(){
        Manager manager = this.getManager();
        int scrollPos = -1;
        if(manager != null)
            scrollPos = manager.getVerticalScroll();

             
        return scrollPos;                
    }
    
    private void paintFloatingText(Graphics g){

	XYRect floatingRect = new XYRect(100,100,70,30);
        
        // since the Field is scrollable, a y offset is need to make sure the label     always displays on the same position on the screen
        int offset_x = 0;
        int offset_y = this.getVerticalScroll();
        
  
        Font fnt = this.floatingLabelFont;
        
        //g.setColor(UIParameters.floating_label_bgColor);
        // set the color as black semi-transparent fror background 
        g.setColor(0xCC000000);
        
        int arc = Math.min(floatingRect.width,floatingRect.height)/2;        
        g.fillRoundRect(offset_x + floatingRect.x ,offset_y + floatingRect.y, floatingRect.width,floatingRect.height,arc,arc);

        //g.setColor(UIParameters.floating_label_fgColor);
        // set the color as white for text 
        g.setColor(0x00FFFFFF);
        
        g.setFont(fnt);

        // Calculate the left-top margins to center the text display
        int margin_x = (int)((floatingRect.width - fnt.getAdvance(this.label))/2);           
        int margin_y = (int)((floatingRect.height - fnt.getHeight())/2);        
        g.drawText(this.label, offset_x + floatingRect.x+margin_x, offset_y + floatingRect.y + margin_y, Graphics.TOP | Graphics.LEFT); 
    }    
}

Last edited by Pan_magically; 05-21-2008 at 12:29 AM..
Offline  
Old 05-21-2008, 12:58 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

Use the get/setGlobalAlpha methods to handle transparency. So in your example you'd do something like:

graphics.setGlobalAlpha(0xCC);
graphics.setColor(0x000000);
// do stuff
// restore global alpha and color
__________________
Do your homework and know how to ask a good question.
Offline  
Old 05-21-2008, 02:01 AM   #3
Pan_magically
Knows Where the Search Button Is
 
Join Date: Apr 2008
Model: 8100
PIN: N/A
Carrier: Hong Kong CSL
Posts: 18
Default

Tyvm. It is working nicely now.

I am more used to using the j2me original Graphics object to draw stuff, and I didn't think a separate method was needed.
Offline  
Old 05-21-2008, 07:57 AM   #4
CELITE
Thumbs Must Hurt
 
Join Date: Dec 2005
Model: 8310
Carrier: Rogers
Posts: 138
Default

The setColor methods of the RIM graphics object do not take the first 8 bits (alpha) into account.
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


ITENA Total C-Ram 8gm Automix Dual Cure self Adhesive Resin Luting Dental Cement picture

ITENA Total C-Ram 8gm Automix Dual Cure self Adhesive Resin Luting Dental Cement

$59.99



Fanuc S-RAM Memory Module A20B-3900-0061/02B picture

Fanuc S-RAM Memory Module A20B-3900-0061/02B

$99.95



AZMCNC 10 Ton Hydraulic Cylinder Ram Single Acting 4

AZMCNC 10 Ton Hydraulic Cylinder Ram Single Acting 4" Inch Stroke Hydraulic Jack

$124.20



FOR DODGE CHRYSLER JEEP RAM Engine Coolant Temperature Sensor OEM MOPAR NEW picture

FOR DODGE CHRYSLER JEEP RAM Engine Coolant Temperature Sensor OEM MOPAR NEW

$11.02



NCR 7616-1301 NCR 72XRT 15

NCR 7616-1301 NCR 72XRT 15" Retail POS Terminal with i3, 8GB Ram 250GB HD No OS

$299.00



Tnt Rescue Equipment Hydraulic Ram R-30   724 picture

Tnt Rescue Equipment Hydraulic Ram R-30 724

$240.00







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